Answer to Question #306365 in Python for xxx

Question #306365

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


1
Expert's answer
2022-03-05T04:12:13-0500
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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS