CS270 Blog

Mid-Sized Python Program: “I’m thinking of a number…”

After studying up on the Python Programming language, I was able to implement random int generators, raw input from the user, loops, and printing.

Again, here’s how the program works:

This Python program will ask the user for his/her name. After taking raw input from the user, it will randomly generate a number between 1-20. The program will print “I’m thinking of a number between 1-20.”

While the number of guesses made are less than 6, the program will print “Take a guess: ”. Each time the users inputs the incorrect number the number of guesses made thus far are stored and incremented. If the user’s guess is less than the actual number, the program prints “Your guess is too low.” If the user’s guess is more than the actual number, the program prints “Your guess is too high”.

If the user guesses the correct number, the program prints “Good job (whatever the user’s name is)! You guessed my number in (however many) guesses!” If the user guesses the wrong number 6 times, the program prints “”Nope. The number I was thinking of was {whatever the randomly-generated number is)”. The program terminates.

Running the program:

Here are some screen shots of how the program works:

This is a link to higher quality screen shots.


  1. cedriccs270blog posted this
To Tumblr, Love PixelUnion