Question 2:
# Three Dice game
# import library
import random
# roll three dice and store the results in the variables
# Add the points from both dice
# display message to guide user on how to use this program
# If total is more than 9, it is 'big'. Else, it is 'small'
# prompt user to guess small or big.
# convert the user input to lower case
# check if the user input is valid
# if the answer was not either small or big,
# shows invalid guess message
# check the value of total
# if it is greater than 9, assign the correct answer as big
# else assign the answer as small
import random
Flag=1
n=1
while(Flag):
R1 = random.randint(1,6)
R2 = random.randint(1,6)
R3 = random.randint(1,6)
Sum = R1+R2+R3
print("Sum = ",Sum)
print("Roll No. ",n)
Guess = (str(input("(Sum > 9 --> big, else --> Small: Guess big or small: "))).lower()
print("Guesss = ",Guess)
if(Sum<=9):
print("Correct Option: SMALL")
if(Guess == "small"):
print("Guess --> Correct")
if(Guess == "big"):
print("Guess --> In-Correct")
if(Guess != "big" or Guess!="small"):
print("Guess --> Invalid Guess")
if(Sum>9):
print("Correct Option: BIG")
if(Guess == "small"):
print("Guess --> In-Correct")
if(Guess == "big"):
print("Guess --> Correct")
if(Guess != "big" or Guess!="small"):
print("Guess --> Invalid Guess")
Flag=int(input("Press 1 to continue or 0 to QUIT:"))
n=n+1
Comments
Leave a comment