subject

I'm a beginner in a computer science 1 class. We're learning to code with python. I've been asked to develop code for a simple math quiz. However, my code will no run and I receive the RESTART but no further output. Please advise. import random

def add(num1, num2):
total_correct = 0

for I in range(2):

num1 = random. randint(1,20)
num2 = random. randint(1,20)
print(num1, "+", num2, '=', end = "")
answer = int(input())

if answer == (num1 + num2):
print("correct")
total_correct+=1
else:
print("incorrect")
return total_correct

def sub(num1, num2):
total_correct = 0

for I in range(2):

num1 = random. randint(1,20)
num2 = random. randint(1,20)
print(num1, "-", num2, "=", end = "")
answer = int(input())

if answer == (num1 - num2):
print("correct")
total_correct+=1
else:
print("incorrect")
return total_correct

def mult(num1, num2):
total_correct = 0

for I in range(2):
num1 = random. randint(1, 20)
num2 = random. randint(1,20)
print(num1, "*", num2, "=", end = "")
answer = int(input())

if answer == (num1*num2):
print("correct")
else:
print("incorrect")
return total_correct

def div(num1, num2):
total_correct = 0

for I in range(2):
num1 = random. randint(1,20)
num2 = random. randint(1,20)
print(num1, "//", num2, "=", end = "")
answer = int(input())

if answer == (num1//num2):
print("correct")
total_correct+=1
else:
print("incorrect")
return total_correct

def mod(num1,num2):

total_correct = 0

for I in range(2):
num1 = random. randint(1,20)
num2 = random. randint(1,20)
print(num1, "%", num2, "=", end = "")
answer = int(input())

if answer == (num1%num2):
print("correct")
else:
print("incorrect")
return total_correct

again = input()

while again == "yes":
correct_answers=0
correct_answers += add() + sub() + mult() + div() + mod()
print("You've completed the quiz, with a score of", correct_answers, "would you like to try again?", "Type yes to take the quiz again")
again = input()

ansver
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 07:30, ghopk5929
In the film "epic 2015," epic is the name for:
Answers: 3
image
Computers and Technology, 22.06.2019 19:20, manny2085
Amedian in the road will be marked with a white sign that has a black arrow going to the left of the median. true false
Answers: 1
image
Computers and Technology, 22.06.2019 22:40, shaylawaldo11
Write a program that defines symbolic names for several string literals (chars between quotes). * use each symbolic name in a variable definition. * use of symbolic to compose the assembly code instruction set can perform vara = (vara - varb) + (varc - vard); ensure that variable is in unsigned integer data type. * you should also further enhance your symbolic logic block to to perform expression by introducing addition substitution rule. vara = (vara+varb) - (varc+vard). required: debug the disassembly code and note down the address and memory information.
Answers: 3
image
Computers and Technology, 24.06.2019 11:00, dirttrackr75
Which of the statements below describe the guidelines for the use of text in presentation programs? a. do not use numbered lists. b. fonts should be appropriate for your audience. c. limit the number of fonts you use to three or four. d. only use bulleted lists for sales promotions. e. select font sizes that are appropriate for your delivery method. f. use font colors that work well with your background. select all that apply
Answers: 1
You know the right answer?
I'm a beginner in a computer science 1 class. We're learning to code with python. I've been asked to...

Questions in other subjects:

Konu
Mathematics, 07.05.2020 02:07