-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNumber Guess.py
46 lines (34 loc) · 1.06 KB
/
Number Guess.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
'''This program is designed to roll a dice and ask the
user for input to guess the sum of the result.
If the user guesses right, the user wins
If the user guesses wrong, the computer wins'''
from random import randint
from time import sleep
def get_user_guess():
guess = int(input('Enter your guess: '))
return guess
def roll_dice(number_of_sides):
x = randint(1, number_of_sides)
first_roll = x
second_roll = randint(1, number_of_sides)
max_val= (2*number_of_sides)
print ('The maximum possible sum is: %d' % (max_val))
guess = get_user_guess()
if guess > max_val:
print ('Invalid input beyond maximum sum')
else:
print ('Rolling... ')
sleep(2)
print ('First roll result is: %d' % (first_roll))
sleep(1)
print ('Second roll result is: %d' % (second_roll))
sleep(1)
total_roll = (first_roll + second_roll)
print (total_roll)
print ('Result...')
sleep(1)
if guess == total_roll:
print ('You are a winner!!!')
else:
print ('You have lost!')
roll_dice(6)