def submit_answer(self): # Try to extract the answer and remainder from the entry boxes. If neither can be converted to an integer, # increase the error counter by 1. try: self.answer = int(self.entAnswer.get()) self.remainder = int(self.entRemainder.get()) # If both values are correct, add it to the answer chain. # Otherwise, an error for you, player. if self.answer == half_number(self.progress) and self.remainder == get_remainder(self.progress): self.remainder = get_remainder(self.progress) self.progress = half_number(self.progress) self.answer_chain.append(self.canAnswers.create_text(0,12 * len(self.answer_chain), anchor = "nw", text = str(self.progress) + " r" + str(self.remainder))) else: self.error_count += 1 except ValueError: self.error_count += 1 # Update the error counter and the current value to be dividing. Also clear the entry boxes. self.error_value.set(str(self.error_count)) self.last_answer_value.set(str(self.progress)) self.entAnswer.delete(0, "end") self.entRemainder.delete(0, "end") # If the player has reached 0, it's time to bring forth the binary entry form. if self.progress == 0: binary_entry(self.forms, self.apps)
answer = int(raw_input(str(progress) + " / 2 = ")) # Did the player enter a string or leave it blank? (Both cases would cause this Error, since they can't be converted to integer. except ValueError: continue else: try: remainder = int(raw_input("remainder: ")) except ValueError: continue else: # Exit the loop. break # If the player's answer and remainder are correct, then pass those answers to the answer chain. # Otherwise, increase the error counter by 1. if answer == half_number(progress) and remainder == get_remainder(progress): remainder = get_remainder(progress) progress = half_number(progress) answer_chain.append([progress, remainder]) else: error_count += 1 while final_binary != binary_answer: print_chain(answer_chain, number, error_count) # Ask the player for the binary value (by reciting the remainders in REVERSE order) and add the binary prefix to it. binary_answer = "0b" + raw_input(str(number) + " in binary: ") # If the player answers incorrectly, increase the error counter by 1. if final_binary != binary_answer: error_count += 1 print_chain(answer_chain, number, error_count)