所以我忙着闲着,写了一个愚蠢的程序:
name = "none"
phone = "none"
while phone == "none":
phone = str(input("Please enter your phone number formatted as (111)111-111 "))
print("loading...")
while name == "none":
name = str(input("Please enter your full name formatted as First, Last "))
print("Thank you for entering your information. Is this correct?")
print("Phone: ", phone, "Name: ", name)
yesno = str(input("Please Enter 'yes', or 'no' to confirm this information."))
if yesno == "yes":
print("Thank you for your time! Your data has been successfully submitted.")
else:
print("Sorry. Please reload the program and enter your data again")
但是当我运行它时我得到错误:意外的EOF。
当我只使用数字而没有标点符号时似乎有效。为什么我不能在我的代码中传递像()那样的标点符号?
答案 0 :(得分:4)
您在Python2中运行代码,其中input
等同于eval(raw_input())
。因此,它会为invalid identifiers抛出EOF错误。
>>> input()
1sdfsdf
File "<string>", line 1
1sdfsdf
^
SyntaxError: unexpected EOF while parsing
因此,要么在Python3中运行代码,要么在Python2中使用raw_input
。(请注意,如果您要使用Python3,str
调用是多余的。)
答案 1 :(得分:0)
python3 test.py
Please enter your phone number formatted as (111)111-111 555 555 5555
loading...
Please enter your full name formatted as First, Last joe, schmoe
Thank you for entering your information. Is this correct?
Phone: 555 555 5555 Name: joe, schmoe
Please Enter 'yes', or 'no' to confirm this information.yes
Thank you for your time! Your data has been successfully submitted.
因此,它在py3中运行良好。