如何检查x是否包含多于或少于7个整数?

时间:2016-09-09 06:39:38

标签: python python-3.x

x = []
y = int(input("Hello, please enter your date of birth in this format: DDMMYYYY"))
x.append(y)
b = len.x()
if b > 7:
    input("Please enter your date of birth correctly in the above format")
elif b < 7:
    input("Please enter your date of birth correctly in the above format")

目前我收到此错误:

  

b = len.x()

     

AttributeError:&#39; builtin_function_or_method&#39;对象没有   属性&#39; x&#39;

对不起,我对python很新,感谢所有的帮助!

2 个答案:

答案 0 :(得分:2)

如果您正在处理日期和时间,可以查看以下主题中给出的解决方案。

Getting input date from the user in python using datetime.datetime

答案 1 :(得分:0)

Python'a len()功能。它不像你认为的那样工作。你做的不对。而不是:

b = len.x()

这样做:

b = len(str(x))

您似乎对len()功能感到困惑。我建议你阅读关于它的Python documentation