简体   繁体   中英

How do I check if x has more or less than seven integers?

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")

At the moment I'm getting this error:

b = len.x()

AttributeError: 'builtin_function_or_method' object has no attribute 'x'

Sorry, I'm quite new to python, thanks for all the help!

You can checkout the solution given in the below thread if you are dealing with date and time.

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

Python'a len() is a function . It does not work like you think it does. What you doing is incorrect. Instead of this:

b = len.x()

Do this:

b = len(str(x))

You seem to be confused about the len() function. I suggest you read the Python documentation about it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM