We created a loop that allowed players to have multiple chances at guessing the correct number.
If you're guess was too high it said
If your guess is too low
And if you got it right
Jon's workshop was a great introduction to programming, and you can clearly see how easy it was for us to make our little game by looking at our code below.
# Generate a random number
import easygui as eg
secret = random.randint(1, 50)
guess = 0
tries = 1
# Ask for your guess
while guess != secret and tries < 4: guess = eg.enterbox("What is your guess? ") guess = int(guess) # Compare your guess against the number if guess < secret: eg.msgbox ("You're guess is too low") elif guess > secret:
eg.msgbox ("You're guess is too high")
elif guess == secret:
eg.msgbox ("You're answer is correct, well done!")
tries += 1
# Tell you if your guess was correct
print "The answer was : ", secret
eg.msgbox ( "The answer was: " + str(secret))
# Loop if less than six guesses
Massive thanks to Jon for leading these sessions, it has been a great experience.
Also, thanks to Mike for his sterling work on the donated LED wallboards