-
Notifications
You must be signed in to change notification settings - Fork 4
/
assignment_15_02_2022.py
48 lines (33 loc) · 1015 Bytes
/
assignment_15_02_2022.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""
1.2 friends want to play a dice game, but have lost the dice.
Create a program to replace the dice. When the program is run, it should roll
the dice and output the result of each dice.
2.Create a while loop that prints your name 5 times in uppercase letters.
3.Create a pyramid pattern object using the number 1.
"""
import random
class Dice:
def __init__(self, sides=6):
self.sides = sides
def roll(self):
return random.randint(1, self.sides)
class DiceGame:
def __init__(self, dice=Dice()):
self.dice = dice
def play(self):
return self.dice.roll()
def print_name(name):
count = 0
while count < 5:
print(name.upper())
count += 1
def print_pyramid(number):
for i in range(1, number + 1):
print(' ' * (number - 1 - i), '1' * (2 * i - 1))
def main():
dice_game = DiceGame()
print(f"The dice rolled {dice_game.play()}")
print_name('Iden')
print_pyramid(10)
if __name__ == '__main__':
main()