Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSiddharth Pande
9,046 Pointskindly find the *** i am doing it wrong
import random
def game():
guess_num = random.randint(1, 10)
print(guess_num)
chance_left = 5
count = 1
print("Guess a number between one and ten and try your luck.")
print("""
Number of chances left is {}
""".format(chance_left))
while True:
chance_left -= 1
try:
user_num = int(input("Enter any Number from 1 to 10: > "))
except ValueError:
print("That's not a valid number! Kindly enter a number only")
print("Number of chance left is {}".format(chance_left))
count += 1
continue
if user_num == guess_num:
print("""
You got it. My secret number was {}
""".format(guess_num))
break
elif count >= 5:
print("""
5 chances completed. You've lost this game!
""")
choice = input("""
If you want to play again Enter 'Y', if not Enter 'N'
> """ )
if choice.upper() == "Y":
game()
else:
print("""
Thank you for Playing. Good Bye!
""")
break
else:
if user_num < guess_num:
print("""
Too Low. Try again!
""")
else:
print("""
Too High. Try again!
""")
count += 1
if chance_left != 1:
print("""
Number of chances left is {}
""".format(chance_left))
else:
print("""
This is your last chance
""")
game()