Monday, February 7, 2011

Exercising Python3

Today I went over some examples in the tutorial which was about guessing the right number 1 to 100 this is the input of the examples:  and after picking the right number that people have to guess this would be the result, the putout:

number = 53
guess = 0
 
while guess != number: 
    guess = int(input ("Guess a number: "))
    if guess > number:
        print("Too high")
    elif guess < number:
        print("Too low")
    else:
        print("Just right =)") 
and after picking the right number that people have to guess this would be the result, the putout: 

Guess a number: 100
Too high
Guess a number: 50
Too low
Guess a number: 75
Too low
Guess a number: 87
Too high
Guess a number: 81
Too high
Guess a number: 53
Just right =)

1 comment:

  1. This is a "classic" example in computer programming. We have a variation of it in our GASP Python Course (see http://www.openbookproject.net/pybiblio/gasp/course/4-highlow.html).

    We should talk about this a bit on Tuesday (I've already got a lot of conversations scheduled for Monday). You can get the computer to generate a "random" number each time the program runs, making playing it more interesting.

    ReplyDelete