Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Duplicate input call

  • Ask the user what is their ID number.
  • Check if it is a valid ID number. (To make our code more simple we only check the length of the string.)
  • Ask again if it was not a valid number.

id_str = input("Type in your ID: ")

if len(id_str) != 9:
   id_str = input("Type in your ID")

print("Your ID is " + id_str)
  • Realize, that if the user types in an incorrect string for the 2nd time, our code does not check it.