Ich möchte Python 10 Fragen stellen und ein Benutzer ihre Antworten eingeben müssen, die funktioniert. Ich möchte aber auch, dass Python mit dem folgenden Code sagt, ob das korrekt ist oder nicht, aber das geht nicht und nur zur nächsten Frage. Kann mir jemand sagen warum? Oder was muss ich ändern? Auch wie stelle ich 10 Fragen speziell mit den Variablen, die ich habe und eine while-Schleife?Python: Wie python eine Summe berechnen, um sicherzustellen, dass eine Eingabe korrekt ist?
import time
import random
question = 0
score = 0
name = input("What is your full name?")
print ("Hello " + name, "welcome to The Arithmetic Quiz")
time.sleep(2)
operand1 = list(range(2, 12))
operators = ["+"]
operand2 = list(range(2, 12))
while question < 10:
user_answer=int(input(str(random.choice(operand1)) + random.choice(operators) + str(random.choice(operand2))))
if operators=='+':
expected_answer==operand1 + operand2
if user_answer==expected_answer:
print('This is correct!')
score = score + 1
question = question + 1
time.sleep(2)
else:
print('This is incorrect!')
question = question + 1
time.sleep(2)
Ich nehme an, basierend auf der Art und Weise, "Eingabe" verwendet wird, dass dies Python 3 ist? – Kupiakos
@Kupiakos Ja, es ist – Ikr