• Home
  • Start
  • iGCSE
    • Basic Print
    • Input & Variables
    • Variable Number Machine
    • IF Statements >
      • Iffy Numbers
    • Simple Loop >
      • While True
    • Rounding
    • Lists >
      • Number Lists
      • Maze
    • Random
  • AS
    • String Slicing
    • SQL Make a DB >
      • SQL Printing your table
      • SQL Selecting Data
      • SQL Add and Delete
      • SQL Updating a Record
  • A2
    • Prolog
  • All
  • Fame
  • Home
  • Start
  • iGCSE
    • Basic Print
    • Input & Variables
    • Variable Number Machine
    • IF Statements >
      • Iffy Numbers
    • Simple Loop >
      • While True
    • Rounding
    • Lists >
      • Number Lists
      • Maze
    • Random
  • AS
    • String Slicing
    • SQL Make a DB >
      • SQL Printing your table
      • SQL Selecting Data
      • SQL Add and Delete
      • SQL Updating a Record
  • A2
    • Prolog
  • All
  • Fame
PYTHON CHALLENGES

Escape Codes

code: TU09 points: 12

Sometimes you want to try something without the program crashing if it does not work out. A good example is if you ask somebody to enter a number and they decide to enter letters or decimals instead.  You could just let Python throw a wobbly, but its better to anticipate it!
The commands to notice are:

​try: - This says that this might not work

except ValueError: This checks that it is a valid number. If somebody enters something that is not a whole number, it will give you the opportunity to say try again...

Exercise 1: Use the code above, but count the number of times that somebody enters an error! Don't let them get away with it.
Powered by Create your own unique website with customizable templates.