python中eof怎么改正_如何在python 3.6中解析时修复意外的EOF?

Im getting the EOF at the end of the program when i try to run it. i dont really know how to fix it. at first i was getting "if" as an invalid syntax but i think i was able to fix that. thanks for the help

while True:

try:

print("Do you want to enter a number?")

print("y - yes")

print("n - no")

choice = int(input("Enter here: "))

if choice == y:

print("")

count = number

for indice in range(1,number + 1, 1):

print(number + indice)

print("")

print("All done")

解决方案

You're missing a except to match try.

Note that there are other issues with your code that will break it, even once you've added except. For example,

if choice == y:

...

This should be 'y' instead of y. As it is, y is expected to be a variable, but you're looking to match on the user input 'y' or 'n'.

Also, if you want a string input, then:

choice = int(input("Enter here: "))

will throw an error if you enter, say, 'y':

invalid literal for int() with base 10: 'y'

Try taking things one line at a time and making sure you understand what's supposed to happen at each point, and test it. Then put them together.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值