import random
question_counter = 0
correct_counter = 0
total_questions = int(input("Hello user! This little program tests your mental math skills"+
"\nHow many questions would you like to be asked?\n\n"))
difficulty = input("\nWhat difficulty of questions would you like to be asked?" +
"\n(beginner) and (intermediate) both ask single step problems" +
"\nIntermediate and (advanced) might ask you results from larger numbers\n\n")
operators_beginner = ['+','-']
operators_other = ['+','-','*','//']
def do_the_math(operators,operands,max,counter,correct):
counter += 1
this_operator = random.choice(operators)
num1 = random.randint(1,max)
num2 = random.randint(1,max)
math_problem = str(num1) + this_operator + str(num2)
if operands == 3:
num3 = random.randint(1,max)
another_operator = random.choice(operators)
advanced_math_problem = math_problem + another_operator + str(num3)
user_answer = int(input("What is " + advanced_math_problem + "?"))
answer = eval(advanced_math_problem)
else:
user_answer = int(input("What is " + math_problem + "?"))
answer = eval(math_problem)
if user_answer == answer:
correct = 1
else:
correct = 0
return correct
while question_counter < total_questions:
question_counter += 1
if difficulty.lower() == 'beginner':
correct_counter += do_the_math(operators_beginner,2,10,question_counter,correct_counter)
elif difficulty.lower() == 'intermediate':
correct_counter += do_the_math(operators_other,2,15,question_counter,correct_counter)
else:
correct_counter += do_the_math(operators_other,3,15,question_counter,correct_counter)
print("You scored " + str(correct_counter/total_questions) + "% correct")
if correct_counter/total_questions > 0.67:
print("Hurray")
elif 0.67 > correct_counter/total_questions > 0.33:
print("Eh")
else:
print("You need help mate!")