7.0k views
2 votes
Write a program that asks a user to predict how many rolls of a single die it will take to reach 100. When all rolling is finished, compare the given answer to the results and let them know if they did well or not.

User PiRSquared
by
4.5k points

1 Answer

0 votes

Answer:

import random

guess = int(input("Make a guess: "))

total = count = 0

while total < 100:

roll = random.randint(1, 6)

total += roll

count += 1

if guess == count:

print("Your guess is correct")

elif guess > count:

print("Your guess is high")

else:

print("Your guess is low")

Step-by-step explanation:

*The code is in Python.

Import the random module to simulate the dice roll

Ask the user to make a guess

Initialize the total and count as 0

Create a while loop that iterates while the total is smaller than 100. Inside the loop, use random to get a random number between 1 and 6 and set it to the roll. Add the roll to the total. Increment the count by 1.

When the loop is done, check the guess and count. If they are equal, that means the guess is correct. If the guess is greater than the count, that means it is high. If the previous cases are not true, then the guess is low.

User Xharlie
by
4.3k points