+ 4
How to take date as input in python. I tried several times but something's going wrong
3 ответов
+ 7
Date and time information should not be used by putting them in int variables. In many cases, calculations or formatting demands matter. It is better to use the datetime class and the datetime module to handle datetime information.
I have put 2 samples in the file.
(1) it uses an input from user, and splits the values to a list. From there it can be converted to a datetime object.
(2) a user input is parsed by strptime and creates a datetime objects. we print date and also weekday name. Then we add a number of days to the date and print it again.
https://code.sololearn.com/cCD9IrCOhXfi/?ref=app
+ 1
a = input()
# when you run you will be prompted to input
print(a)
# prints what you input as a string
+ 1
dateStr = input('Enter date in format DD/MM/YY\n')
day, month, year = map(lambda x: int(x),dateStr.split('/'))
print(day,month, year)