I have been given a basic python problem that requires me to make a simple addition quiz. However, I cannot seem to return my count variable which is supposed to update the number of correct questions the user has answered, which makes it stuck at 0. I have tried defining the variable count in every function containing it as an argument but still does not work. Say if the user were to answer 4 questions and got 3 correct, it would display it as "You have answered 4 questions with 3 correct", but instead it displays "You have answered 4 questions with 0 correct".
Every time your check_solution and menu_optionfunctions get called, you initialize count = 0. This means every time the user requests another question, count gets reset to 0, twice. You're going to want to remove those count = 0 calls, and you also want to capture your updates to count within menu_option. Your final program should look something like this:
import random
def get_user_input():
count = 0
user_input = int(input("Enter 1 to play or press 5 to exit: "))
while user_input > 5 or user_input <= 0:
user_input = int(input("Invalid menu option. Try again: "))
menu_option(user_input, count)
if user_input == "5":
print("Exit!")
return user_input
def get_user_solution(problem):
answer = int(input(problem))
return answer
def check_solution(user_solution, solution, count):
curr_count = count
if user_solution == solution:
curr_count += 1
print("Correct.")
else:
print("Incorrect.")
print(curr_count)
return curr_count
def menu_option(index, count):
if index == 1:
num1 = random.randrange(1, 21)
num2 = random.randrange(1, 21)
randsum = num1 + num2
problem = str(num1) + " " + "+" + " " + str(num2) + " " + "=" + " "
user_answer = get_user_solution(problem)
count = check_solution(user_answer, randsum, count) # count returned by check_solution is now being captured by count, which will update your count variable to the correct value
return count
def display_result(total, correct):
if total == 0:
print("You answered 0 questions with 0 correct.")
print("Your score is 0%. Thank you.")
else:
score = round((correct / total) * 100, 2)
print("You answered", total, "questions with", correct, "correct.")
print("Your score is", str(score) + "%.")
def main():
option = get_user_input()
total = 0
correct = 0
while option != 5:
total = total + 1
correct = menu_option(option, correct)
option = get_user_input()
print("Exiting.")
display_result(total, correct)
main()
You need catch the return from check_solution(user_answer, randsum, count) and return that count
As the comment stated, you are initializing count to 0 every time your check_solution or menu_option is called.
It looks like you want to use count = count the variable being passed to your function.
Just a quick edit:
You actually don't need to return count. In Python, variables are passed by reference so your count will get updated as long as it's being passed to your functions.
You have the option of initializing count to 0 before all functions, thus creating a global variable. Then you won't need to declare it on any function nor pass it as argument.
This is a culmination of several errors in logic.
You give count to functions as input and immediately overwrite it.
I would instead say def menu_option(index, count=0):. This will set count=0 if no variable is supplied (creating a default), otherwise it will set count as whatever you pass into the function
Your check_solution() function returns a number, but when you call it with check_solution(user_answer, randsum, count) you never assign this returned value to anything/use it again.
You can assign this to a variable (say output) and then return output instead of return count
Fixing these still doesn't fully solve the problem, but gets a little bit closer (now it gets stuck on "you answered x questions with 1 correct"):
import random
def get_user_input(count = 0):
user_input = int(input("Enter 1 to play or press 5 to exit: "))
while user_input > 5 or user_input <= 0:
user_input = int(input("Invalid menu option. Try again: "))
menu_option(user_input, count)
if user_input == "5":
print("Exit!")
return user_input
def get_user_solution(problem):
answer = int(input(problem))
return answer
def check_solution(user_solution, solution, count):
count = 0
if user_solution == solution:
count += 1
print("Correct.")
else:
print("Incorrect.")
return count
def menu_option(index, count=0):
if index == 1:
num1 = random.randrange(1, 21)
num2 = random.randrange(1, 21)
randsum = num1 + num2
problem = str(num1) + " " + "+" + " " + str(num2) + " " + "=" + " "
user_answer = get_user_solution(problem)
output = check_solution(user_answer, randsum, count)
return output
def display_result(total, correct):
if total == 0:
print("You answered 0 questions with 0 correct.")
print("Your score is 0%. Thank you.")
else:
score = round((correct / total) * 100, 2)
print("You answered", total, "questions with", correct, "correct.")
print("Your score is", str(score) + "%.")
def main():
option = get_user_input()
total = 0
correct = 0
while option != 5:
total += 1
correct = menu_option(option, correct)
option = get_user_input()
print("Exiting.")
display_result(total, correct)
main()
I think a more simplistic approach would look something like:
import random
def generate_question():
num1 = random.randint(1, 25)
num2 = random.randint(1, 25)
question = '{} + {} = '.format(num1, num2)
answer = num1 + num2
return question, answer
def main():
correct = 0
total = 0
option = True
while option != '5':
total += 1
question, answer = generate_question()
user_guess = int(input(question))
if user_guess == answer:
print('Correct.')
correct += 1
else:
print('Incorrect.')
option = input("Enter 5 to exit, or anything else to play again")
print('You answered {} questions with {} correct'.format(total, correct))
main()
Related
The error I get from the program is undefined variable.
*
# Python 3.9.4
# import sys
# print(sys.version)
SubjectT = input("Enter your subject: ")
Tutor_Name = input("Enter your name: ")
Iterate = int(input("How many students are there? "))
# Set counter
# create count for each student
Accumulate = 0
for i in range(Iterate): # It will run how many time based on Iterate input
Score = float(input("Enter score: "))
Counter = True
while Counter:
if 80 <= Score < 100:
Accumulate1 = Accumulate + 1
elif 80 > Score >= 65:
Accumulate2 = Accumulate + 1
elif 65 > Score >= 50:
Accumulate3 = Accumulate + 1
elif Score < 50:
Accumulate4 = Accumulate + 1
else:
print("The number is a negative value or incorrect")
Again = input("Enter yes for restarting again or if you want to exit the program please press anything: ")
if Again in ("y", "Y", "YES", "Yes", "yes"):
continue
else:
break
print(f"Subject title:", {SubjectT}, "\nTutor:", {Tutor_Name})
print("Grade", " Number of students")
print("A", "Students: ", Accumulate1)
print("B", "Students: ", Accumulate2)
print("C", "Students: ", Accumulate3)
print("D", "Students: ", Accumulate4)
This is my first post in Stackoverflow.
pardon me for any inappropriate content.
Thanks you so much.
You stated
Counter = True
without iteration, thus it will run indefinitely. With while loop you need to set some constraints.
I realised why you had the While loop in there, but it still wasn't working for me effectively - if all answers were within range it never terminated. This should work for you, it does for me. I changed it so it checks every time somebody enters a score that it is within the correct range, so you don't have to repeat the whole loop in the event of incorrect values
SubjectT = input("Enter your subject: ")
Tutor_Name = input("Enter your name: ")
NoOfStudents = int(input("How many students are there? "))
# Set counter
# create count for each student
Accumulate = 0
Accumulate1 = 0
Accumulate2 = 0
Accumulate3 = 0
Accumulate4 = 0
def validRange(score):
if 0 <= score <=100:
return True
else:
return False
i = 1
while (i <= NoOfStudents): # It will run how many time based on Iterate
validInput = False
while (not validInput):
Score = float(input("Enter score: "))
if ( not validRange(Score)):
print("The number is a negative value or incorrect")
else:
validInput = True
if 80 <= Score < 100:
Accumulate1 = Accumulate1 + 1
elif 80 > Score >= 65:
Accumulate2 = Accumulate2 + 1
elif 65 > Score >= 50:
Accumulate3 = Accumulate3 + 1
elif Score < 50:
Accumulate4 = Accumulate4 + 1
i = i+1
print(f"Subject title:", {SubjectT}, "\nTutor:", {Tutor_Name})
print("Grade", " Number of students")
print("A", "Students: ", Accumulate1)
print("B", "Students: ", Accumulate2)
print("C", "Students: ", Accumulate3)
print("D", "Students: ", Accumulate4)
I'm kinda new to programming in general, just started to really get into python.
And I'm working on a number guesser project.
import random
def main(): # main function
print("Welcome to the number guesser game")
range_func()
max_guess_number(lower_range_cut, upper_range_cut)
evaluation(random_number, total_guesses)
def range_func(): # allows user to select a range for the number guess
print("Please select a range in which you would like to guess.")
lower_range_cut = int(input("Lower boundary limit: "))
global lower_range_cut
upper_range_cut = int(input("Upper boundary limit: "))
global upper_range_cut
random_number = random.randint(lower_range_cut,upper_range_cut)
global random_number
return lower_range_cut, upper_range_cut, random_number
def max_guess_number(low,high): # returns the total number of guesses
total_numbers = (high - low) + 1
total_guesses = 0
while (2**total_guesses) < total_numbers:
total_guesses += 1
print ("You have a total of %d guesses\n"
"for your range between %d to %d"
% (total_guesses, low, high))
global total_guesses
return total_guesses
def evaluation(random_number, total_guesses): # evaluates the users input
guess_count = 0
while guess_count < total_guesses:
user_guess = int(input("Your guess: "))
print("Your guess is: %d" % (user_guess))
if (random_number == user_guess):
print("You got it ")
break
elif user_guess > random_number:
print("Guess lower!")
guess_count += 1
else:
print("Guess higher!")
guess_count += 1
if __name__ == "__main__":
main()
One problem I've experienced while writing that, is that I wasn't able to execute this program without redefining each variables as a global variable. Just by returning the values from one function, I was not able to access e.g. the second returned variable upper_range_cut from the range_function
It there a way to handle that somehow shorter?
Also I'm happy about every note on the code itself (readability, function use, length). I know it could have made this code a lot shorter maybe by using list comprehension, but I don't really have the eye for seeing opportunities in this area yet.
So thanks for any help!
KiliBio
You're pretty much there. You can remove all globals, then just store the values returned from each function to local variables, and pass them in to new functions.
The only other changes I've made below are:
Breaking out of the evaluation loop if the answer is guessed correctly.
Printing a message if no guess is found in the given time. See: Else clause on Python while statement
The bottom two lines allow the script to be run from the command line. See: What does if __name__ == "__main__": do?
Otherwise you're looking good.
import random
def main(): # main function
print("Welcome to the number guesser game")
lower, upper, rand = range_func()
total_guesses = max_guess_number(lower, upper)
evaluation(rand, total_guesses)
def range_func(): # allows user to select a range for the number guess
print("Please select a range in which you would like to guess.")
lower_range_cut = int(input("Lower boundary limit: "))
upper_range_cut = int(input("Upper boundary limit: "))
random_number = random.randint(lower_range_cut, upper_range_cut)
return lower_range_cut, upper_range_cut, random_number
def max_guess_number(low,high): # returns the total number of guesses
total_numbers = (high - low) + 1
total_guesses = 0
while (2**total_guesses) < total_numbers:
total_guesses += 1
print ("You have a total of %d guesses\n"
"for your range between %d to %d"
% (total_guesses, low, high))
return total_guesses
def evaluation(random_number, total_guesses): # evaluates the users input
guess_count = 0
while guess_count < total_guesses:
guess_count += 1
user_guess = int(input("Your guess: "))
print("Your guess is: %d" % (user_guess))
if (random_number == user_guess):
print("You got it!")
break
else:
print "Sorry, you didn't guess it in time. The answer was: %d" % random_number
if __name__ == '__main__':
main()
You don't need to define global. You can just assign the values you are returning from a function to variable(s).
A simple example:
def add(a, b):
"""This function returns the sum of two numbers"""
return a + b
Now in your console, you could do following
# print the return
>>> print(add(2, 3))
5
# assign it to a variable
>>> c = add(2, 3)
>>> c
5
In your main function you need to assign the values which are returned by different functions to variables which you can further pass to other functions.
def main(): # main function
print("Welcome to the number guesser game")
lower_range_cut, upper_range_cut, random_number = range_func()
total_guesses = max_guess_number(lower_range_cut, upper_range_cut)
evaluation(random_number, total_guesses)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
is there a way to add a second loop to a code. So the question says to create a quiz which I've done however, for the last hour I've being trying to add a second loop so the quiz does it three times:
import random
score = 0
questions = 0
loop = 0
classnumber = ("1", "2", "3")
name = input("Enter Your Username: ")
print("Hello, " + name + ". Welcome to the Arithmetic Quiz")
classno = input("What class are you in?")
while classno not in classnumber:
print(
"Enter a valid class. The classes you could be in are 1, 2 or 3.")
classno = input("What class are you in?")
while questions < 10:
for i in range(10):
number1 = random.randint(1, 10)
number2 = random.randint(1, 10)
op = random.choice("*-+")
multiply = number1*number2
subtract = number1-number2
addition = number1+number2
if op == "-":
print("Please enter your answer.")
questions += 1
print(" Question", questions, "/10")
uinput = input(str(number1)+" - "+str(number2)+"=")
if uinput == str(subtract):
score += 1
print("Correct, your score is: ", score,)
else:
print("Incorrect, the answer is: " + str(subtract))
score += 0
if op == "+":
print("Please enter your answer.")
questions += 1
print(" Question", questions, "/10")
uinput = input(str(number1)+" + "+str(number2)+"=")
if uinput == str(addition):
score += 1
print(" Correct, your score is: ", score,)
else:
print(" Incorrect, the answer is: " + str(addition))
score += 0
if op == "*":
print("Please enter your answer.")
questions += 1
print(" Question", questions, "/10")
uinput = input(str(number1)+" * "+str(number2)+"=")
if uinput == str(multiply):
score += 1
print(" Correct, your score is: ", score,)
else:
print(" Incorrect, the answer is: " + str(multiply))
score += 0
First, please consider using functions in your code. Functions make everything neater and functions help make code reusable.
Second, there are a lot of areas where the code is superfluous. It is performing unnecessary checks in spots and several sections of the code could be rearranged to reduce the overall length and increase readability.
Nonetheless, here's a revised version of your code with some of those suggestions implemented:
import random
def RunQuiz():
name = input("Enter Your Username: ")
print("Hello, " + name + ". Welcome to the Arithmetic Quiz")
score = 0
questions = 0
loop = 0
classnumber = ("1", "2", "3")
classno = input("What class are you in?")
while classno not in classnumber:
print("Enter a valid class. The classes you could be in are 1, 2 or 3.")
classno = input("What class are you in?\n>>> ")
# End while input
# Run the 10 question quiz
for questions in range(1,11):
number1 = random.randint(1, 10)
number2 = random.randint(1, 10)
op = random.choice("*-+")
multiply = number1*number2
subtract = number1-number2
addition = number1+number2
print("Please enter your answer.")
print(" Question" + str(questions) "/10")
if( op == "-"):
# Subtraction
uinput = input(str(number1)+" - "+str(number2)+"=")
# Make it an int for proper comparison
uinput = int(uinput)
if uinput == subtract:
score += 1
print("Correct, your score is: %d" %(score,))
else:
print("Incorrect, the answer is: " + str(subtract))
score += 0
elif( op == "+"):
# Addition
uinput = input(str(number1)+" + "+str(number2)+"=")
uinput = int(uinput)
if uinput == addition:
score += 1
print(" Correct, your score is: %d" % (score,))
else:
print(" Incorrect, the answer is: " + str(addition))
score += 0
elif( op == "*" ):
# Multiplication
uinput = input(str(number1)+" * "+str(number2)+"=")
uinput = int(uinput)
if uinput == multiply:
score += 1
print(" Correct, your score is: %d" % (score,))
else:
print(" Incorrect, the answer is: " + str(multiply))
score += 0
# End if( op )
# End For 10 questions
print("\nFinal Score: %d/10" % (score,))
# End RunQuiz()
def main():
# Run the quiz 10 times
for RunCount in range(3):
print("Running quiz #%d\n" % (RunCount,))
RunQuiz()
# End For
# End main
# Call main on script execution
main()
Obviously you can rearrange the code to suit your needs. (For example, I did not know if you want the name & class number to be entered every time).
If you want the whole thing to run 3 times then put for i in xrange(3): above the first lines of the quiz then indent the rest of the code to the loop. If that is what you actually want. Good luck!
I'm currently learning Python and am creating a maths quiz.
I have created a function that loops, first creating a random maths sum, asks for the answer and then compares the input to the actual answer; if a question is wrong the player loses a point - vice versa. At the end a score is calculated, this is what I'm trying to return at the end of the function and print in the main.py file where I receive a NameError 'score' is not defined.
I have racked my head on trying to figure this out. Any help / suggestions would be greatly appreciated!
#generateQuestion.py
`def generate(lives, maxNum):
import random
score= 0
questionNumber = 1
while questionNumber <=10:
try:
ops = ['+', '-', '*', '/']
num1 = random.randint(0,(maxNum))
num2 = random.randint(0,10)
operation = random.choice(ops)
question = (str(num1) + operation + str(num2))
print ('Question', questionNumber)
print (question)
maths = eval(str(num1) + operation + str(num2))
answer=float(input("What is the answer? "))
except ValueError:
print ('Please enter a number.')
continue
if answer == maths:
print ('Correct')
score = score + 1
questionNumber = questionNumber + 1
print ('Score:', score)
print ('Lives:', lives)
print('\n')
continue
elif lives == 1:
print ('You died!')
print('\n')
break
else:
print ('Wrong answer. The answer was actually', maths)
lives = lives - 1
questionNumber = questionNumber + 1
print ('Score:', score)
print ('Lives:', lives)
print('\n')
continue
if questionNumber == 0:
print ('All done!')
return score
`
My main file
#main.py
import random
from generateQuestion import generate
#Welcome message and name input.
print ('Welcome, yes! This is maths!')
name = input("What is your name: ")
print("Hello there",name,"!" )
print('\n')
#difficulty prompt
while True:
#if input is not 1, 2 or 3, re-prompts.
try:
difficulty = int (input(' Enter difficulty (1. Easy, 2. Medium, 3. Hard): '))
except ValueError:
print ('Please enter a number between 1 to 3.')
continue
if difficulty < 4:
break
else:
print ('Between 1-3 please.')
#if correct number is inputted (1, 2 or 3).
if difficulty == 1:
print ('You chose Easy')
lives = int(3)
maxNum = int(10)
if difficulty == 2:
print ('You chose Medium')
lives = int(2)
maxNum = int(25)
if difficulty == 3:
print ('You chose Hard')
lives = int(1)
maxNum = int(50)
print ('You have a life count of', lives)
print('\n')
#generateQuestion
print ('Please answer: ')
generate(lives, maxNum)
print (score)
#not printing^^
'
I have tried a different method just using the function files (without the main) and have narrowed it down to the problem being the returning of the score variable, this code is:
def generate(lives, maxNum):
import random
questionNumber = 1
score= 0
lives= 0
maxNum= 10
#evalualates question to find answer (maths = answer)
while questionNumber <=10:
try:
ops = ['+', '-', '*', '/']
num1 = random.randint(0,(maxNum))
num2 = random.randint(0,10)
operation = random.choice(ops)
question = (str(num1) + operation + str(num2))
print ('Question', questionNumber)
print (question)
maths = eval(str(num1) + operation + str(num2))
answer=float(input("What is the answer? "))
except ValueError:
print ('Please enter a number.')
continue
if answer == maths:
print ('Correct')
score = score + 1
questionNumber = questionNumber + 1
print ('Score:', score)
print ('Lives:', lives)
print('\n')
continue
elif lives == 1:
print ('You died!')
print('\n')
break
else:
print ('Wrong answer. The answer was actually', maths)
lives = lives - 1
questionNumber = questionNumber + 1
print ('Score:', score)
print ('Lives:', lives)
print('\n')
continue
if questionNumber == 0:
return score
def scoreCount():
generate(score)
print (score)
scoreCount()
I think the problem is with these last lines in main:
print ('Please answer: ')
generate(lives, maxNum)
print ('score')
You are not receiving the returned value. It should be changed to:
print ('Please answer: ')
score = generate(lives, maxNum) #not generate(lives, maxNum)
print (score) # not print('score')
This will work.
The way it works is not:
def a():
score = 3
return score
def b():
a()
print(score)
(And print('score') will simply print the word 'score'.)
It works like this:
def a():
score = 3
return score
def b():
print(a())
I need help with this program that I'm writing. It asks random mathematical questions. It chooses between +, - and x. Here's my code
import random
def questions():
name=input("What is your name: ")
print("Hello there",name,"!")
choice = random.choice("+-x")
finish = False
questionnumber = 0
correctquestions = 0
while finish == False:
if questionnumber < 10 | questionnumber >= 0:
number1 = random.randrange(1,10)
number2 = random.randrange(1,10)
print((number1),(choice),(number2))
answer=int(input("What is the answer?"))
questionnumber = questionnumber + 1
if choice==("+"):
realanswer = number1+number2
if answer==realanswer:
print("That's the correct answer")
correctquestions = correctquestions + 1
else:
print("Wrong answer, the answer was",realanswer,"!")
if choice==("x"):
realanswer = number1*number2
if answer==realanswer:
print("That's the correct answer")
correctquestions = correctquestions + 1
else:
print("Wrong answer, the answer was",realanswer,"!")
elif choice==("-"):
realanswer = number1-number2
if answer==realanswer:
print("That's the correct answer")
correctquestions = correctquestions + 1
else:
print("Wrong answer, the answer was",realanswer,"!")
else:
finish = True
else:
print("Good job",name,"! You have finished the quiz")
print("You scored " + str(correctquestions) + "/10 questions.")
questions()
The output:
What is your name: s
Hello there s !
6 - 9
What is the answer?-3
That's the correct answer
9 - 8
What is the answer?1
That's the correct answer
9 - 7
What is the answer?2
That's the correct answer
8 - 3
What is the answer?4
Wrong answer, the answer was 5 !
5 - 6
What is the answer?1
Wrong answer, the answer was -1 !
8 - 7
What is the answer?1
That's the correct answer
3 - 5
What is the answer?2
Wrong answer, the answer was -2 !
4 - 5
What is the answer?1
Wrong answer, the answer was -1 !
7 - 2
What is the answer?5
That's the correct answer
7 - 1
What is the answer?6
That's the correct answer
Good job s ! You have finished the quiz
You scored 6/10 questions.
Now the program is running fine but it asks the questions with the same operator (+, -, x) every time I start the program a different operator questions happen but I want to run it so it actually asks different adding, subtracting, multiplication questions inside the program so all the questions that it asks it will be different questions like x, + and - every different question.
It should help if you move the choice part inside the loop:
while not finish: # better than finish == False
choice = random.choice("+-x")
# etc
import random
correct = 0
name = input("Please enter your name: ")
for count in range(10):
num1 = ranom.randint(1, 100)
num2 = radom.randint(1, 100)
symbol = rndom.choice(["+", "-", "*"])
print("Please solve:\n", num1, symbol, num2)
user = int(input(""))
if symbol == "+":
answer = num1 + num2
elif symbol == "-":
answer = num1 - num2
elif symbol == "*":
answer = num1 * num2
if user == answer:
print("Wong u wetard")
correct = correct + 1
else:
print("correct")
print(name, ", You Got", correct, "Out Of 10")
After while finish == false put this !
choice = random.choice("+-x")
I have attempted the same problem that you face, and after looking at your code I made the changes detailed below. the code works and it is (relatively) neat and concise.
def name_enter():
global name
name = ""
while name == "" or len(name) > 25 or not re.match(r'^[A-Za-z0-9-]*$', name):
name = input("Please enter your name: ")
enter_class()
def enter_class():
global class_choice
class_choice = None
while class_choice not in ["1","3","2"]:
class_choice = input("Please enter you class (1, 2, 3): ")
print("\nClass entered was " + class_choice)
mathsquestion()
def mathsquestion():
global qa, score
qa, score = 0, 0
for qa in range(0,10):
qa = qa + 1
print("The question you are currently on is: ", qa)
n1, n2, userans = random.randrange(12), random.randrange(12), ""
opu = random.choice(["-","+","x"])
if opu == "+":
while userans == "" or not re.match(r'^[0-9,-]*$', userans):
userans = input("Please solve this: %d" % (n1) + " + %d" % (n2) + " = ")
prod = n1 + n2
elif opu == "-":
while userans == "" or not re.match(r'^[0-9,-]*$', userans):
userans = input("Please solve this: %d" % (n1) + " - %d" % (n2) + " = ")
prod = n1 - n2
else:
while userans == "" or not re.match(r'^[0-9,-]*$', userans):
userans = input("Please solve this: %d" % (n1) + " x %d" % (n2) + " = ")
prod = n1 * n2
userans = int(userans)
prod = int(prod)
if prod == userans:
score = score + 1
print("Well done, you have got the question correct. Your score is now: %d" % (score))
else:
print("Unfortunatly that is incorrect. The answer you entered was %d" % (userans) + " and the answer is actually %d" % (prod))
print("Your final score is: %d" % (score))
name_enter()
This is a very different code but should do the same thing. It's also much shorter and neater.
import random
correct = 0
name = input("Please enter your name: ")
for count in range(10):
num1 = random.randint(1, 100)
num2 = random.randint(1, 100)
symbol = random.choice(["+", "-", "*"])
print("Please solve:\n", num1, symbol, num2)
user = int(input(""))
if symbol == "+":
answer = num1 + num2
elif symbol == "-":
answer = num1 - num2
elif symbol == "*":
answer = num1 * num2
if user == answer:
print("Correct!")
correct = correct + 1
else:
print("Incorrect")
print(name, ", You Got", correct, "Out Of 10")