[Tutor] One of my 'baby step' programs

Luke Paireepinart rabidpoobear at gmail.com
Mon Oct 2 06:49:31 CEST 2006

Alan Gilfoy wrote:
> -code block-
> number = 3
> running = True
> while running:
>    guess = int(raw_input("Please enter a number : ")) #lets user guess a number
>    if guess == number:
>        print "Yay, you got the right number, good for you. But you 
> don't get any prizes. Do I look like a walking ATM to you?"
>        running = False #this causes the guess-again loop to start.
>    elif guess < number:
>        print "No, my number is higher than that"
>    else:
>        print "No, my number is lower than that."
> else:
>    print "The number-guessing loop is over."
I had no idea you could have an 'else' tied to a 'while' loop.
> print "Done."
> -end code block-
> Darnit, it's very simple, but I still like the fac tthat is does 
> something to user input.
you should look into the 'random' module.
You can generate a random integer with the random.randint() function.
Then us programmers who peek at your code can't cheat and choose 3 every 
time :)
Good luck on your project!
Any idea what it'll be yet?

More information about the Tutor mailing list