import random
name=input("What is your name?")
print ("Alright",name,"welcome to your maths quiz")
score=0
level_of_difficulty= input("What level of difficulty are you working at? Press 1 for low, 2 for intermediate or 3 for high")
if level_of_difficulty == 1:
for question_num in range(1, 11):
ops = ['+', '-', '*']
number_1=random.randrange(1,10)
number_2=random.randrange(1,10)
operation = random.choice(ops)
maths = eval(str(number_1) + operation + str(number_2))
print('\nQuestion number: {}'.format(question_num))
print ("The question is",number_1,operation,number_2)
Answer=int(input ("What is your answer:"))
if Answer==maths:
print ("Correct")
score=score+1
else:
print ("Incorrect. The actual answer is",maths)
print("Well done you scored",score,"out of 10")
if level_of_difficulty == 2:
for question_num in range(1, 11):
ops = ['+', '-', '*']
number_1=random.randrange(1,20)
number_2=random.randrange(1,20)
operation = random.choice(ops)
maths = eval(str(number_1) + operation + str(number_2))
print('\nQuestion number: {}'.format(question_num))
print ("The question is",number_1,operation,number_2)
Answer=int(input ("What is your answer:"))
if Answer==maths:
print ("Correct")
score=score+1
else:
print ("Incorrect. The actual answer is",maths)
print("Well done you scored",score,"out of 10")
if level_of_difficulty == 3:
for question_num in range(1, 11):
ops = ['+', '-', '*',"/"]
number_1=random.randrange(1,20)
number_2=random.randrange(1,20)
operation = random.choice(ops)
maths = eval(str(number_1) + operation + str(number_2))
print('\nQuestion number: {}'.format(question_num))
print ("The question is",number_1,operation,number_2)
Answer=int(input ("What is your answer:"))
if Answer==maths:
print ("Correct")
score=score+1
else:
print ("Incorrect. The actual answer is",maths)
print("Well done you scored",score,"out of 10")
爲什麼這不起作用?沒有無效的語法。所以我不知道爲什麼它不起作用。爲什麼在我輸入名字後這段代碼不起作用?
什麼Python版本您使用的? –
'爲什麼這不起作用,沒有無效的語法,所以我不知道爲什麼它不能正常工作' - 您將需要更多的信息來吸引更多的幫助。 SO不是大量代碼的個人調試服務。 – Sinkingpoint
我正在使用pyscripter,但我認爲它的3.1「 – Ibrahim