I'm trying to write a simple number estimate program. In this special program, Python is assessing a number on which the user is thinking, not the other round.
My code returns an unbound sound error.
Besides, it seems all too cumbersome. How can I shorten it?
Thank you. Random imports take a number from the number of random numbers = "" DF numerus (): while correct: print "Think number between 1 and 50" raw_input ("Hit key when ready") number = randink (1,50) Answer = Raw_input ("your number:% d ?. y / n & gt;"% number) if answer == 'Y': print "Great!" Raw_input ("Hit a key to exit.") Elif Answer == 'n': greater_or_smaller () Other: Print "Please type y or n" def greater_or_smaller (): while correct: greater_or_smaller = raw_input (" Your number is greater if more_or_group == 'g': number = randint (number, 50) answer = raw_input ("is your number% d? Y / n & gt;"% number) if less than% _ or% Answer: = "Y": print "hooray!" Answer to Alif == 'N': greater_ or_group () elif greater_or_smaller == 's': number = randint (1, number) answer = Raw_input ("what Your number% d? Y / n & gt; "% number" if answer == 'Y': print "hooray!" Answer to Alif == 'N': big_or_mailer () numberGuesar ()
itemprop = "text">
this: If: greater_or_smaller ['g', 's']: number = if answer == 'Y': print "hurray" (if your number is% d? Y / n & Gt; "% is number) Answer = raw_input (if your number is% d) if more_or_group == 'g' and randint (1, number) answer =! "Elif's answer == 'N': greater than_m_mellier () In addition, you may have to write a little function to handle the interaction with the user in order to ensure that Answer is in the list of answered answers. Something like:
def get_input (prompt_text, valid_options): x = raw_input (prompt_text) while x is not in valid_payment: Print X, "Valid values are not expected:", valid_position back x
No comments:
Post a Comment