我正在做一个数学测验,需要帮助输出
Q1: 31 + 11 = **42** Correct
其中42由用户输入,然后在同一行中输出正确和不正确
import random
# setting up variables that i will need
NUMEBR_OF_QUES = 0
count = 0
correctCount = 0
incorrectCount = 0
levelOne = 1
levelTwo = 2
levelThree = 3
addition = 1
subtraction = 2
# Start asking user questions to set up code
quizType = int(input("Available quiz type: Enter 1 for addition and 2 for subtraction: "))
diffSelection = int(input("Difficulty Level: Enter 1 for 1-digit, 2 for 2-digit, and 3 for 3-digit: "))
# This is if the user chooses addition
while NUMEBR_OF_QUES < 10 and diffSelection == 1 and quizType == 1:
levOneQues = random.randint(0, 9)
levOneQuesTwo = random.randint(0, 9)
NUMEBR_OF_QUES = NUMEBR_OF_QUES + 1
if quizType == addition and diffSelection == levelOne:
count = count + 1
print("Q", count, ": ", levOneQues, " + ", levOneQuesTwo, "=")
total = int(levOneQues + levOneQuesTwo)
anwser = int(input())
if anwser == total:
correctCount = correctCount + 1
print("Q", count, ": ", levOneQues, " + ", levOneQuesTwo, "= ", anwser, "Correct")
else:
incorrectCount = incorrectCount + 1
print("Q", count, ": ", levOneQues, " + ", levOneQuesTwo, "= ", anwser, "Incorrect")
出于测试的目的,我把1作为第一个问题,第二个问题,输出如下
Available quiz type: Enter 1 for addition and 2 for subtraction: 1
Difficulty Level: Enter 1 for 1-digit, 2 for 2-digit, and 3 for 3-digit: 3
Q 1 : 278 + 761 =
3
Q 1 : 278 + 761 = 3 Incorrect
你需要它来打印问题吗?例如,您是否可以将输入改为提问
代码:
这只会在提供应答后发送到终端,因此它包括正确或不正确的标签
您使用了太多的
if
来限制功能。while NUMEBR_OF_QUES < 10 and diffSelection == 1 and quizType == 1
,while
循环只在执行add 1-digit
时才进入,因此3-digit
不起作用李>if quizType == addition and diffSelection == levelOne:
也只有在执行{f-string
而不是用逗号打印李>print(chr(27) + "[2J")
和newline = " "
可能会有所帮助print ("\033[A \033[A")
code:
result:
相关问题 更多 >
编程相关推荐