-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrollingdice.py
More file actions
42 lines (36 loc) · 1.41 KB
/
Copy pathrollingdice.py
File metadata and controls
42 lines (36 loc) · 1.41 KB
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
'''Design a project where as an input student will give a static number (between 1 to 6) and then roll the dice which randomly generate some value between 1 to 6. The winning situation arrives when the given static/fixed number exactly same to the number came after rolling the dice.'''
import random
import time
def roll_dice():
'''Rolls the dice and returns a random number between 1 and 6'''
return random.randint(1, 6)
def main():
'''Main function'''
print('Welcome to the dice rolling game!')
print('You will be asked to enter a number between 1 and 6.')
print('The dice will be rolled and a random number between 1 and 6 will be generated.')
print('If the number you entered is the same as the number generated by the dice, you win!')
print('If not, you lose!')
print('Good luck!')
print()
time.sleep(2)
while True:
try:
number = int(input('Enter a number between 1 and 6: '))
if number < 1 or number > 6:
print('Number must be between 1 and 6!')
continue
break
except ValueError:
print('Invalid input!')
continue
print('Rolling the dice...')
time.sleep(2)
print('The value is:', roll_dice())
if roll_dice() == number:
print('You win!')
else:
print('You lose!')
print('Better Luck next time :(')
if __name__ == '__main__':
main()