COMPUTER SCIENCE CAFÉ
  • WORKBOOKS
  • BLOCKY GAMES
  • GCSE
    • CAMBRIDGE GCSE
  • IB
  • A LEVEL
  • LEARN TO CODE
  • ROBOTICS ENGINEERING
  • MORE
    • CLASS PROJECTS
    • Classroom Discussions
    • Useful Links
    • SUBSCRIBE
    • ABOUT US
    • CONTACT US
    • PRIVACY POLICY
  • WORKBOOKS
  • BLOCKY GAMES
  • GCSE
    • CAMBRIDGE GCSE
  • IB
  • A LEVEL
  • LEARN TO CODE
  • ROBOTICS ENGINEERING
  • MORE
    • CLASS PROJECTS
    • Classroom Discussions
    • Useful Links
    • SUBSCRIBE
    • ABOUT US
    • CONTACT US
    • PRIVACY POLICY
Picture
PYTHON GUESSING GAME
This is a good game to aid the learning of Python loops, user input, error checking and if statements.
import random
num = random.randint(1,10)
guess = 0
score = 10

while guess != num:
   try:
      guess = int(input("Please enter a number between 1 and 10: "))
      if guess > num:
         print ("You guess too high")
         score = score - 1
      elif guess < num:
         print ("You guess too low")
         score = score - 1
   except:
      print ("You entered an invalid value")
print ("That is correct")
print ("Your score is: " + str(score))

Please feel free to copy and paste the code from above. 

Picture
SUGGESTIONS
We would love to hear from you
SUBSCRIBE 
To enjoy more benefits
We hope you find this site useful. If you notice any errors or would like to contribute material then please contact us.