← Back to Community
##### math quiz
Profile icon
AboodCS1204

import random

name = input().title()
print (name, ", Welcome to this math quiz! ")
score = 0
question = 0

while question < 5:
symbol = random.randint(1,2)
num1 = random.randint(1,25)
num2 = random.randint(1,25)
if symbol == 1:
print("What is", num1, "+", num2)
ans = num1 + num2
elif symbol == 2:
print("What is", num1, "-", num2)
ans = num1 - num2
while True:
try:
user_ans = int(input())
except ValueError:
print ("type using numbers.")
continue
else:
break
if user_ans == ans:
score += 1
else:

`.css-19sk4h4{position:relative;}.css-1bu6gr6{-webkit-align-items:stretch;-webkit-box-align:stretch;-ms-flex-align:stretch;align-items:stretch;border-width:0;border-style:solid;box-sizing:border-box;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-basis:auto;-ms-flex-preferred-size:auto;flex-basis:auto;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;outline:none;min-height:0;min-width:0;position:relative;}.css-1n2m10r{padding:var(--space-8);border-radius:var(--border-radius-4);background-color:var(--background-higher);}.css-1hwur6u{-webkit-align-items:stretch;-webkit-box-align:stretch;-ms-flex-align:stretch;align-items:stretch;border-width:0;border-style:solid;box-sizing:border-box;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-basis:auto;-ms-flex-preferred-size:auto;flex-basis:auto;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;outline:none;min-height:0;min-width:0;padding:var(--space-8);border-radius:var(--border-radius-4);background-color:var(--background-higher);}.css-1ubbl1f{padding:var(--space-4);padding-left:var(--space-4);padding-right:var(--space-2);font-family:var(--font-family-code);font-size:14px;line-height:var(--line-height-small);overflow-x:auto;word-break:break-word;white-space:break-spaces;overflow-wrap:anywhere;}`question += 1``

print ("you scored", score, "/5")
print("You have scored", score100/5, "%")
if score
100/5 >= 50 :
print(name, " you have passed the quiz")

else:
print(name,",you have failed the quiz.")

Voters
Profile icon
AlfiePatterson
Profile icon
AboodCS1204