#WSQ06 – Pick a Number

The main purpose of this program is that the user guess a number from 1 to 100. Display the user the number of tries  and it give you hints of low and high, close to the number.

The first thing you need to do is import the random library in order to generate a random number each time the program executes, this random number will be between 1 and 100. Also you need to use a counter staring at 0, later you will use it to display the number of times until the user guess the number.

2016-02-18 (4)

In this case I use a while loop because I know that the point to stop its when the guess of the user its equal to the random number, so as long as the guess of the user its different, the while loop will repeat but with several conditions using if, elif that includes when the number its out of both boundries and when the number is high or low.

2016-02-18 (2)

At the end when the user wins, the while loop ends and the random number is printed, the number of time you try as well.

2016-02-18 (3)

I did two runs, you can see the random number its not the same.

code:https://www.dropbox.com/s/2jt4unflqycacgs/wsq6-pick.py?dl=0

#TC101

CC BY-SA 4.0 #WSQ06 – Pick a Number by programmingtc101 is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.