如果您输入单词而不是字母,我不知道如何将功能放置在输出“无效输入”的位置。我想使用检查,但是当我搜索它时,我没有希望。
counter = 0
import random
easy = input("Enter 1 for easy 2 for medium and 3 for hard")
if easy == "1":
for i in range(10):
x = random.randint(1,10)
y = random.randint(1,10)
ops = random.randint(1,3)
if ops == 1:
print("What is the answer of ",x,"+",y,)
answer = x+y
ans = int(input())
if ans == answer:
print("Correct")
counter = counter +1
else:
print("Incorrect")
elif ops == 2:
print("What is the answer of ",x,"-",y,)
answer = x-y
ans = int(input())
if ans == answer:
print("Correct")
counter = counter +1
else:
print("Incorrect")
elif ops == 3:
print("What is the answer of ",x,"*",y,)
answer = x*y
ans = int(input())
if ans == answer:
print("Correct")
counter = counter +1
else:
print("Incorrect")
print("You got ",counter,"/10")