O'Reilly logo

Learn to Program with Python 3: A Step-by-Step Guide to Programming by Irv Kalb

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

© Irv Kalb 2018
Irv KalbLearn to Program with Python 3https://doi.org/10.1007/978-1-4842-3879-0_6

6. Loops

Irv Kalb1 
(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, this chapter covers the following topics:
  • User’s view of the game

  • Loops

  • while statement

  • First loop in a real program

  • Increment and decrement

  • Running a program multiple ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required