View difference between Paste ID: ZCMWe9mJ and YbXYnC70
SHOW: | | - or go back to the newest paste.
1-
Guess a number between 1 and 100: HiLeo
1+
# Simple guess the number game
2-
Guess lower!
2+
3-
Guess a number between 1 and 100: 20
3+
from random import randint
4-
Guess lower!
4+
5-
Guess a number between 1 and 100: 10
5+
def findnumber():
6-
Guess lower!
6+
	number = randint(1,100)
7-
Guess a number between 1 and 100: 1
7+
	print number
8-
Guess lower!
8+
	guess = raw_input("Guess a number between 1 and 100: ")
9-
Guess a number between 1 and 100: 0
9+
	tries = 0
10-
Guess lower!
10+
	while guess != number:
11-
Guess a number between 1 and 100: -9
11+
		if not guess.isalpha():
12-
Guess lower!
12+
			print "That is not a number!"
13
		elif guess < number:
14
			print "Guess higher!"
15
			tries += 1
16
		elif guess > number:
17
			print "Guess lower!"
18
			tries += 1
19
			findnumber()
20
		else:
21
			print "You have won!"
22
			tries += 1
23
			print "It took you %d tries!" % tries
24
25
print findnumber()