【发布时间】:2020-11-23 18:32:14
【问题描述】:
我刚刚开始使用 Internet 上提供的信息进行编程(python3)。现在我正在学习如何使用 try/except。我的问题是我编写的代码在 Windows 10 的命令提示符下运行良好,但在抛出错误的 shell(Atom/Hydrogen)中运行良好(第 6 行,NameError),因为我没有定义变量“fish” ,我知道通常情况相反,但我只是想了解我是否犯了错误。代码如下:
>try:
>> fish = int (input("please enter your age "))
>except:
>> print("That's not a number ")
>> exit(0)
>if fish <= 15:
>> parentLicense = input ("have one of your parents have a license? (yes/no) ")
>> if parentLicense == "yes":
>>> print ("You can fish")
>> else:
>>> print("So sad, you or one of your parents need a license")
【问题讨论】:
标签: python-3.x command-prompt try-except hydrogen