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 with loop

  • A while loop would be a better solution.
  • This works, but now we have duplicated the input call and the text is different in the two cases. DRY
  • We can't remove the first call of input as we need the id_str variable in the condition of the while already.

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

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

print("Your ID is " + id_str)