import random
Number = random.randrange(100)+1
Tryz = 1
Attempt = int(raw_input("Please enter the number of attempt you want: "))
Guess = int(raw_input("Please guess the the number: "))
while Attempt != Tryz and Guess != Number:
Tryz += 1
if Guess < Number:
Guess = int(raw_input("Try a higher number: "))
else:
Guess = int(raw_input("Try a lower number: "))
if Tryz == Attempt:
print "You have ran out of tries the correct number is ", Number
else:
print "You have guessed it in ", Tryz, "tries"
print "The correct number was ", Number
Vusumuzi
0
Light Poster
Recommended Answers
Jump to PostThe else statement in the following code executes if the number is equal to or greater than since you don't test for an equal condition and will print "try a lower number" when equal. You should test for greater than only as the while loop catches the equal condition. Your …
Jump to PostMy program is here if you want to compare http://www.daniweb.com/software-development/python/code/287950/classic-number-guess-game-python-ternary-operator-demonstration
All 7 Replies
Vusumuzi
0
Light Poster
woooee
814
Nearly a Posting Maven
TrustyTony
888
pyMod
Team Colleague
Featured Poster
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
fonzali
0
Light Poster
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
fonzali
0
Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.