【发布时间】:2015-11-12 20:19:46
【问题描述】:
我用过:
day = int(input('Please input the day you were born: e.g 8th=8 21st = 21 : '))
month = int(input('Please input the month you were born: e.g may = 5 december = 12 : '))
year = int(input('Please input the year you were born: e.g 2001 / 1961 : '))
if day == int and month == int and year == int:
但它总是即使它是一个整数也说它是错误的。
【问题讨论】:
-
type(day) is int等 -
@axiom 你真的应该使用
isinstance。 -
你使用的是 Python2 还是 Python3?
-
由于将输入调用包装在
int(中,您的类型检查变得无用,因为只有两种可能性:1)日、月和年都是整数;或 2) 您的程序在前 3 行中因ValueError而崩溃,if将永远不会运行。 -
您能否更详细地说明“但即使是整数也总是说它是错误的。”?您的错误输入和输出到底是什么?