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 trialdanielplaisimnd
6,837 Pointspython
i guess errors on line 7 where the while loop is started
import random
rand_num = random.randint(1, 10) # to hold our random number
guessed_nums = [] # to hold our guesses number
allowed_guesses = 5 #number of guesses are allowed
while len(guessed_nums < allowed_guesses):
guess = input("Guess a number between 1 and 10: ") # get an integer input
try:
player_num = int(guess) # player number is guessing
except:
print (" That s not a whole number!")
break
if not player_num > 0 or not player_num< 11: # conditional statement
print ("That number isnt between 1 and 10:")
break
guessed_num.append(player_num) #add player number to our guess number
if player_num == rand_num: # display win is player num is equal random num
print("You re Win! My number was {}.".format(rand_um)) # pass the random number
print("It took you {}.tries.".format(len(guessed_nums))) # pass the guess number
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: # when the number they guess is not in our list
print("Sorry! my number was {}.".format(rand_num))
1 Answer
Ryan Carson
23,287 PointsYou need to wrap just the guessed_nums
in parenthesis, like this
while len(guessed_nums) < allowed_guesses: