I started learning Python yesterday so I am really proud that I was able to create this and actually get it to work exactly as I want it to! :D
Obviously, I did some specific research for some commands with Google to help me out with the harder stuff (for me) such as creating a loop with while True until break and stuff like that :)
Here's the code!
while True:
import random
number = random.randint(1,50)
tries = 0
guess = 0
print "Find the number!"
print "It's between 1 and 50, you have 5 tries!"
while guess != number and tries <5:
guess = input("What's your guess?: ")
if guess > number:
print "Too high!"
elif guess < number:
print "Too low!"
tries = tries + 1
if guess == number:
print "You got it! The number was:", number
else:
print "You lost! The number was:", number
answer = raw_input ("Play again?: ")
if answer.strip() in "n N no No NO".split():
break
Edited by Azrian, 16 February 2010 - 02:23 PM.
Added the name of the language used in the title


Sign In
Create Account

Back to top










