【发布时间】:2014-02-26 20:33:41
【问题描述】:
我正在使用一个子程序,我认为这是我的问题的原因,这是我的代码:
def sub1():
dob=input('Please enter the date of the person (dd) : ')
while dob not in ['01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31']:
print('you have entered an incorrect day')
dob=input('Please enter the date of the person (dd) : ')
sub1()
if month == '02' :
if dob == ['30','31'] :
print('You have entered incorrecty')
sub1()
可变月份只是01,02,03,04,05,06,07,08,09,10,11,12
错误信息是: 文件“C:/Users/Akshay Patel/Documents/TASK 2/task 两个月 dob.py”,第 13 行,在 如果 dob == ['30','31'] :
NameError: name 'dob' 未定义
【问题讨论】:
-
修复你的缩进......它在 python 中有所作为。您的错误消息听起来像是您在原始来源中的缩进是正确的。
dob仅在sub1中定义,因此当您在sub1之外使用它时,它不适合您
标签: python subroutine