Roll the Dice, where each dice has from 1 to 6 dots on each side. Two dice will be rolled. Use the random function to generate a random integer between the beginning and ending range of dot possibilities.
Your program should generate a random number. Then display a message to prompt a player to enter his/her name and then guess the number. They have 5 chances to get the number correct. If they guess the right one, display to them that they guessed the correct number in the number of guesses. If they did not guess itin 5 attempts, display a message telling them they were not successful in guessing the correct number and tell them which number it was. Allow the player to play again.
import random
result = random.randint(2,12)
name = str(input("Enter your name: "))
attempt = 0
while attempt < 5:
prediction = int(input("Try to predict: "))
if attempt < 4 and prediction == result:
print(f"{name}, you guessed {result} using {attempt+1} attempts")
break
elif attempt < 4 and prediction != result:
print("Incorrect")
attempt+=1
elif attempt == 4:
print(f"{name}, you were not successful in guessing the correct number, the correct number is {result} ")
break
Comments
Leave a comment