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 trial

Python Python Basics (Retired) Pick a Number! Any Number! The Solution

Emma Schwartz
Emma Schwartz
4,019 Points

The rest of it was fine,but after I guesed the right number it said this:It took you [5, 4, 3, 2] tries.How do I fix it?

My code was ~Python~ ~import random

rand_num = random.randint(1, 10) guessed_nums = [] allowed_guesses = 5

while len(guessed_nums) < allowed_guesses: guess = input("Guess a number between 1 and 10: ")

try: player_num = int(guess) except: print("That's not a whole number!") break

if not player_num > 0 or not player_num < 11: print("That number isn't between 1 and 10!") break

guessed_nums.append(player_num)

if player_num == rand_num: print("You win! My number was {}.".format(rand_num)) print("It took you {} tries.".format(guessed_nums)) break else: if rand_num > player_num: print("Nope! My number is higher than {}. Guess #{}".format( player_num, len(guessed_nums))) else: print("Nope! My number is lower than {}. Guess #{}".format( player_num, len(guessed_nums))) continue

if not rand_num in guessed_nums: print("Sorry! My number was {}.".format(rand_num))~

1 Answer

format(guessed_nums)) whereas you are doing len(guessed_nums))) when you dont get the right number.. see the difference?