All pastes #834342 Raw Edit

Miscellany

public text v1 · immutable
#834342 ·published 2007-12-28 03:32 UTC
rendered paste body
from gasp import *
import time

right = 0
wrong = 0
qs_asked = 0

var1 = 0
var2 = 15
var3 = 0
var4 = 15


def welcome():
	stars = "*" * 40 #need to make the length of the stars the length of tuple item 1 "welcome..."
	print "\n".join((stars, "Welcome! This program will ask you mathematics questions and automatically", "adjust the difficulty level depending on how well you do. Enjoy! :)", stars))

def seconds():
	return "seconds" if int(t2-t1) != 1 else "second"

def questions():
	return "questions" if right != 1 else "question"

def end():
	print "you answered", right, questions(), "out of", num_qs_wanted, "correctly in", int(t2-t1), seconds()



welcome()



num_qs_wanted = raw_input("how many problems would you like to be asked to solve? ")
while not num_qs_wanted.isdigit():
	print "Oops! That was not a valid number. Try again..."
	num_qs_wanted = raw_input("how many problems would you like to be asked to solve? ")


t1 = time.time()


"""
This is the future time limit to be implemented

time_limit = raw_input("do you want a time limit? ")
while time_limit.isdigit():
	print "Oops! That was not a valid response. Try typing 'yes' or 'no'."
	time_limit = raw_input("do you want a time limit? ")

#need something that checks to see if input is YES or NO

if str.lower(time_limit) =="yes":
	time_to_stop = num_qs_wanted * 10 SECONDS

if seconds passed == time_to_stop:
	return end()

also need a stopwatch showing how much time is left
"""


for qs_asked in range(int(num_qs_wanted)):
 
	a = random_between(var1, var2)
	b = random_between(var3, var4)
	c = a * b


	d = raw_input("what's %s * %s? "%(a,b))
	while not d.isdigit():
		print "Oops! That was not a valid number. Try again..."
		d = raw_input("what's %s * %s? "%(a,b))


	if int(d) == c:
		print "correct!"
		right = right + 1
		var1 += 1
		var2 += 1
		var3 += 1
		var4 += 1


	else:
		print "incorrect, the answer is ", c
		wrong = wrong + 1
		if var2 !=1:
			var2 -= 1
		if var4 !=1:
			var4 -= 1



t2 = time.time()

end()



"""

after implementing the stop watch.. need to clean the code, adding appropriate comments and putting declarations and such in an easily distinguishable location.


"""