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 trialchailatte
941 PointsHow to readjust arguments based on input?
This is from the Number Game app except the reverse version where I have the computer guess my number. I've looked through the old posts for this app and have realized the need to adjust my arguments (lower, upper) after the initial guess, but I'm not sure how to go about it. This is what I have so far.
import random
wrong_guess = []
guess = random.randint(1, 10)
def game():
while len(wrong_guess) < 5:
lower = ()
upper = ()
guess = random.randint(lower, upper)
answer = input("Is your number " + str(guess) + "? Enter Y/N: ")
if answer.upper() == 'Y':
print("Ah ha! {} was your number. That was fun!".format(guess))
play_again = input("Wanna play again? Enter Y/N: ")
if play_again.upper() == 'Y':
game()
else:
print("OK! Let's play again next time!")
break
else:
wrong_guess.append(guess)
hl_ans = input("Was my guess too high or too low? Enter H/L: ")
if hl_ans.upper() == 'H':
upper = guess
game()
elif hl_ans.upper() == 'L':
lower = guess
game()
game()