+ 4

How to take date as input in python. I tried several times but something's going wrong

28th May 2020, 12:27 PM
Sejal Tapadiya
Sejal Tapadiya - avatar
3 Antworten
+ 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
28th May 2020, 5:14 PM
Lothar
Lothar - avatar
+ 1
a = input() # when you run you will be prompted to input print(a) # prints what you input as a string
28th May 2020, 12:39 PM
Slick
Slick - avatar
+ 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)
28th May 2020, 2:48 PM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar