I am trying to code a guessing game in JES using the pseudo code below:
Generate a random single digit number
Have the user guess the number
If the user does not guess correctly give them a clue – indicate whether the number is even or odd and ask the user to guess again.
If the user does not guess correctly, give another clue – indicate whether the number is a multiple of 3 and ask the user to guess again.
If the user does not guess correctly, give another clue – indicate whether the number is less than or greater than 5 and ask the user to guess again.
If the user does not guess correctly,
display a box indicating the correct answer and the number of guesses the user made.
If the user has guessed correctly, display a box indicating their guess is correct and how many guesses were required
Show the amount of time the user played the guessing game.
There are so many conditions I have no clue how to have the program ask each question, analyze the answer, and if the condition isn't met, to move on to the next one.
Below is my current code which obviously is incorrect. I am also aware there may be indenting issues in this post.
from random import *
from time import *
def main():
a= randrange( 0, 11 )
start= clock()
numberOfGuesses= 0
userGuess= requestInteger( " Please guess a single digit number " )
while userGuess != a:
userGuess= requestInteger( " Please guess a single digit number " )
if userGuess % 2 == 0:
showInformation( " Incorrect! Please try again. Hint: The number is even " )
if userGuess % 2 != 0:
showInformation( " Incorrect! Please try again. Hint: The number is odd " )
if userGuess % 3 != 0:
showInformation( " Incorrect! Please try again. Hint: The number is not a multiple of 3 " )
if userGuess > 5:
showInformation( " Incorrect! Please try again. Hint: The number is greater than 5 " )
if userGuess < 5:
showInformation( " Incorrect! Please try again. Hint: The number is greater than 5 " )
else:
showInformation( " Correct " )
Aucun commentaire:
Enregistrer un commentaire