【发布时间】:2016-01-14 21:54:54
【问题描述】:
今天我在写这个程序
from random import randint
def practice():
command = input("Welcome to math practice! Type mult tables to practice multiplication tables, or simp add for single digit addition")
if command == "mult tables":
while True:
first_value_x = randint(2, 12)
second_value_x = randint(2, 12)
number_x = int(input("%s x %s" % (first_value_x, second_value_x )))
if number_x == first_value_x * second_value_x:
print("Correct!!")
else:
print("You did not get the answer correct.")
elif command == "simp add":
while True:
first_value_simp_add = randint(1,9)
second_value_simp_add = randint(1,9)
number_simple_add = int(input("What is %s + %s" %(first_value_simp_add, second_value_simp_add)))
if number_simple_add == first_value_simp_add + second_value_simp_add:
print("Well done!")
else:
print("You did not the answer correct")
else:
print("The command you entered does not exist. Please retype a command")
practice()
practice()
但是,我不断收到此错误
SyntaxError: unexpected EOF while parsing
或者更具体的
Traceback (most recent call last):
File "/Users/student/Desktop/math practice.py", line 49, in <module>
practice()
File "/Users/student/Desktop/math practice.py", line 6, in practice
command = input("Welcome to math practice! Type mult tables to practice multiplication tables, or simp add for single digit addition")
File "<string>", line 1
simp add
^
SyntaxError: unexpected EOF while parsing
或
Traceback (most recent call last):
File "/Users/student/Desktop/math practice.py", line 49, in <module>
practice()
File "/Users/student/Desktop/math practice.py", line 6, in practice
command = input("Welcome to math practice! Type mult tables to practice multiplication tables, or simp add for single digit addition")
File "<string>", line 1
mult tables
^
SyntaxError: unexpected EOF while parsing
当我尝试在输入中输入mult tables 或simp add 命令时。
我已经多次重新查看我的代码并阅读了一堆其他SyntaxError: unexpected EOF while parsing 线程,但仍然找不到我出错的地方。对不起,如果很明显我对这种东西很陌生。请帮忙!
【问题讨论】: