[英]error when user entering dot in python input
im wondering why is我想知道为什么
File "<string>", line 1
.
^
SyntaxError: unexpected EOF while parsing
coming when i execute following script and including dot in input.当我执行以下脚本并在输入中包含点时就会出现。
answer = input('enter 1: ')
if answer == 1:
print('nice')
else:
print('please enter "1"')
return
I have been wondering this pretty long, and now im trying to ask here if someone could help me.我一直在想这很长一段时间,现在我想在这里问是否有人可以帮助我。 So i can't include dots or anything else that basic letters and numbers my input.所以我不能包括点或其他任何基本字母和数字的输入。 I thought there could be easy way to find this thing out.我认为可能有简单的方法来找出这件事。 There is other code i need to fix below, with same error.我需要在下面修复其他代码,但错误相同。
email = str(input('required* Your mail: '))
print('your mail is : ' + email)
now, it needs to include dot and at mark.现在,它需要包括点和标记。
The code here seems ok, except for the fact you're using return without a function.这里的代码看起来没问题,除了你使用没有 function 的 return 的事实。
And the code wouldn't work when I put I type 1, because you need to cast the var "aswer".当我输入 1 时,代码不起作用,因为您需要转换 var “aswer”。
The code should be like this:代码应该是这样的:
answer = int(input('enter 1: '))
if answer == 1:
print('nice')
else:
print('please enter "1"')
You are putting a string and you are checking if is this a number , that is your error, so if you want to ask every time if the answer is wrong you could do this:您正在输入一个字符串,并且您正在检查这是否是一个数字,这是您的错误,所以如果您想每次都询问答案是否错误,您可以这样做:
while True:
answer = input('enter 1: ')
if answer == "1":
print('nice')
break
else:
print('please enter "1"')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.