import random
import dice
totalGames = 0
correctGuesses = 0
incorrectGuesses = 0
consecutiveCorrectGuesses = 0
consecutiveIncorrectGuesses = 0
die_count = [0,0,0,0,0,0,0]
print("Petals Around the Rose")
print("----------------------")
print("")
print("The name of the game is 'Petals Around the Rose'. The name of the game is important. The computer will roll five dice and ask you to guess the score for the roll. The score will always be zero or an even number. Your mission, should you choose to accept it, is to work out how the computer calculates the score. If you succeed in working out the secret and guess correctly three times in a row, you become a Potentate of the Rose.")
print("")
validateGame = 'y'
playGame = (input("would you like to play Petals Around the Rose [y/n]?"))
print()
while validateGame == 'y':
if playGame == 'n':
validateGame = 'n'
print("No worries... another time perhaps... :)")
elif playGame == 'y':
validateGame = 'y'
else: #playGame != 'y' and 'n':
print("Please either enter 'y' or 'n'")
playGame = (input("would you like to play Petals Around the Rose [y/n]?"))
print()
while playGame == 'y':
die1 = random.randint(1,6)
die2 = random.randint(1,6)
die3 = random.randint(1,6)
die4 = random.randint(1,6)
die5 = random.randint(1,6)
dice.display_dice(die1 ,die2 , die3, die4, die5)
Dice_Output_List = [die1 ,die2 , die3, die4, die5]
userGuess = int(input(("Please enter your guess for the roll: ")))
print()
totalGames +=1
score = 0
for randNumber in Dice_Output_List:
if randNumber == 5:
score += 4
elif randNumber == 3:
score += 2
else:
score += 0
if userGuess == score:
print("Well done!, you've guessed it!")
print("")
correctGuesses +=1
consecutiveCorrectGuesses +=1
consecutiveIncorrectGuesses = 0
elif userGuess % 2 != 0:
print("No sorry, its", score, "not", userGuess,".", "The score is always even.")
print("")
incorrectGuesses +=1
consecutiveIncorrectGuesses +=1
consecutiveCorrectGuesses = 0
elif userGuess != score:
print("No sorry, its", score, "not", userGuess,".")
print("")
incorrectGuesses +=1
consecutiveIncorrectGuesses +=1
consecutiveCorrectGuesses = 0
if consecutiveCorrectGuesses == 3:
consecutiveCorrectGuesses = 0
print("Congratulation, you have figured out the secret.")
print("Make sure you do not tell anyone.")
print("")
elif consecutiveIncorrectGuesses == 3:
consecutiveIncorrectGuesses = 0
print("")
print("Hint: the name of the game is important...Petals Around the Rose.")
print("")
die_count[die1] = die_count[die1] + 1
die_count[die2] = die_count[die2] + 1
die_count[die3] = die_count[die3] + 1
die_count[die4] = die_count[die4] + 1
die_count[die5] = die_count[die5] + 1
playGame = (input("Roll dice again [Y/N]?"))
print("")
if playGame == 'n':
validateGame = 'n'
elif playGame == 'y':
validateGame == 'y'
while playGame != 'n':
print("Please either enter 'y' or 'n'")
playGame = (input("Roll dice again [Y/N]?"))*
Problem: Once the game is finished, the user is asked whether they want to play with the question "Roll dice again [Y/N]?". If the user inputs something other than ‘y’ and ‘n’, the question is asked again; and on the repeated questions ‘y’ does not load the game but ‘n’ ends the game.
EG
roll dice again [y/n]? ‘h’
"please either enter ‘y’ or ‘n’"
roll dice again [y/n]? ‘x’
"please either enter ‘y’ or ‘n’"
roll dice again [y/n]? ‘y’
"please either enter ‘y’ or ‘n’"
roll dice again [y/n]?
when ‘y’ is inputted the question is repeated but It should allow the user to play again.
>Solution :
The problem is with this block:
while playGame != 'n':
print("Please either enter 'y' or 'n'")
playGame = (input("Roll dice again [Y/N]?"))
You are just asking for input until the input is n. I believe you need to check if it is unequal to both y and n.
code:
while playGame != 'n' and playGame != 'y':
print("Please either enter 'y' or 'n'")
playGame = (input("Roll dice again [Y/N]?"))*