Turtle Guess A Number
Turtle Guess A Number
Session 6
Logic can be used to make fun games. Try it! Design a game where the player must pick a
number between one and ten. Can they guess it?
E
number=pick a random number guess=type number into input box
PL
write("No!")
2. Import the Turtle library. Label the title bar and hide the Turtle symbol.
#guess
guess=numinput("Guess", "Pick a number between 1 and 10.")
E
8. Check to see if the player's guess is correct:
#check guess
if guess==number:
write("Yes! You are correct!")
PL
else:
write("No!")
9. Run the program to play the game. Did you guess the number?
TIP: Add font=("Arial", 20)
to make the text larger.
No!
#check guess
if guess==number:
write("Yes! You are correct!", font=("Arial", 20))
else:
write("No! The number is " +str(number)+ ".")
SA
11. Run the program to play the game again. Did you guess the number?
TIPS:
• When testing the program make the range smaller such as random.randint(1, 2)