python - Fill_in_blank_game. Unable to select level -


whenever type in 1 of level options console prints

"c-3po: entry not compute sir." , prmpts again.

so in other words unable select level of game. enter in padawan example, 1 of selections , instead of showing paragraph blanks code runs while loop of chosen_level not in choices.

padawan_level = "luke skywalker son of \n darth __1__! \n boba fett     son of __2__ fett. \nis type in:\n stormtroopers known     __3__ troopers\n yoda jedi __4__ \n"padawan_inputs = ['darth vader','jango','clone','master']  jedi_level = "\n han solo owed money jabba __1__ \n princess leia\'s last name __2__.\n han solo's ship called __3__ falcon.\n boba fett's ship called __4__ 1.\n"jedi_inputs = ['hutt','organa','millennium','slave']  master_level = "princess leia's home planet __1__.\n darth vader born on planet__2__.\n senetor palpatine known darth __3__.\n luke skywalker raised unlce __4__.\n" master_inputs = ['alderaan','tatooine','sidious','owen']  def select_level(): """prompts user level'"""     prompt = "please select game difficulty typing in!\n"     prompt += "possible choices include padawan, jedi, , master.\n"     choices = {x:"padawan" x in ("padawan", '1',)}     choices.update({y:"jedi" y in ("jedi", '2',)})     choices.update({z:"master" z in ("master", '3')})     chosen_level = raw_input(prompt).lower()     while chosen_level not in choices:         print "c-3po: entry not compute sir."         chosen_level = raw_input(prompt).lower()  print "c-3po: you've selected " + str(choices[chosen_level]) + '!\n' return choices[chosen_level]   def get_answers(level):     global padawan_level     global padawan_inputs     global jedi_level     global jedi_inputs     global master_level     global master_inputs     if level == 'padawan':         return (padawan_level, padawan_inputs)     if level == 'jedi':         return (jedi_level, jedi_inputs)     if level == 'master':         return (master_level, master_inputs)     print "c-3po: error, try again."     raise valueerror  def ask_question(blank_game, blank_num, answer, max_try = 3):     trys_left = max_trys     to_replace = '__' + str(blank_num) + '__'     prompt = make_display(blank_game, to_replace, trys_left, max_trys)     user_guess = raw_input(prompt).lower()     while user_guess != answer.lower() , trys_left > 1:         trys_left -= 1         prompt = make_display(blank_game, to_replace, trys_left, max_trys)         user_guess = raw_input(prompt).lower()     if trys_left > 1:         print '\ncorrect!\n'         return (blank_game.replace(to_replace, answer), blank_num + 1)     else:         return (none, blank_num + 1)   def make_display(current_mode, to_replace, trys_left, max_trys):     """returns string user."""     prompt = "\nc-3po: current data reads such:\n{}\n\n"     prompt += "c-3po: should in place of space {}?"     prompt = prompt.format(current_mode, to_replace)     if trys_left == max_trys:         return prompt     new_prompt = "incorrect sir...don't blame me. i'm interpreter."     if trys_left > 1:         new_prompt += "excuse me sir, might inquire what's going on? {} trys left!\n"     else:         new_prompt += "if may so, have {} try left!\n"     return new_prompt.format(trys_left) + prompt   def find_max_guess():     print "c-3po: have 4 guesses per question"     return 4   def play_game():     level = select_level()     blank_game, answers = get_answers(level)     max_guess = find_max_guess()     current_blank = 1     while current_blank <= len(answers):         blank_game, current_blank = ask_question(blank_game, current_blank, answers[current_blank - 1], max_guess)         if blank_game none:             print "c-3po: we're doomed."             return false      print blank_game + "\noh, yes, that\'s good, that.\n"     return true   play_game() 

here code.

you have few problems code. first padawan_inputs, jedi_inputs, , master_inputs should each on new line. next segment:

print "c-3po: you've selected " + str(choices[chosen_level]) + '!\n' return choices[chosen_level] 

should indented in select_level function. in ask_question error trys_left = max_trys because max_trys isn't defined, remove s. onto question, right choices {'1': 'padawan', 'jedi': 'jedi', '2': 'jedi', 'master': 'master', 'padawan': 'padawan', '3': 'master'} , check if users lowercase input array:

chosen_level = raw_input(prompt).lower() while chosen_level not in choices:     print "c-3po: entry not compute sir."     chosen_level = raw_input(prompt).lower() 

none of values in choices lowercase only. either remove lower() or fix choices have valid entry items. when removed lower() level selected.

chosen_level = raw_input(prompt) 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -