© Irv Kalb 2016

Irv Kalb, Learn to Program with Python, 10.1007/978-1-4842-2172-3_6

6. Loops

Irv Kalb

(1)Mountain View, California, USA

In this chapter, we’ll build a “Guess the Number” program. The computer will pick a random number between 1 and 20, and the user will have five attempts to guess the number. For every incorrect guess, the computer will let the user know if the correct answer is higher or lower than the user’s guess. If the user doesn’t guess the answer in five attempts, the program will tell the user what the number was.

To learn how to build a game like this, we cover the following topics in this chapter:

  • User’s view of the game

  • Loops

  • while statement

  • First loop in a real program

  • Increment and decrement

  • Running a program multiple times ...

Get Learn to Program with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.