Beispiel #1
0
	def __init__ (self, forms, apps):
		self.forms = forms
		self.apps = apps
		self.parent = forms["scorecard"]				# scorecard is the parent for all widgets in this class.
		
		self.error_count = apps["game"].error_count		# Pass the error counter to one local to this window.
		self.grade = grade(self.error_count)			# Obtain a grade based on the number of errors made by the player.
		
		# Get rid of the root and binary forms. They are no longer needed.
		forms["root"].destroy()
		del(apps["game"])
		forms["binary"].destroy()
		del(apps["binary"])
		
		self.init_ui()
Beispiel #2
0
				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)
	print "Grade:" + grade(error_count)
	# Ask if the player wishes to try again. Convert the answer to lowercase.
	#If the player answers with anything but "n" the player will start again.
	keep_playing = raw_input("Try again? (y/n) ").lower()