0

How take user input in time format HH:MM in python language

Help

6th May 2020, 5:12 AM
Mohan Raj Murugan
Mohan Raj Murugan - avatar
5 odpowiedzi
+ 2
Oh, I see. The code I wrote was created for a single input, like 9:55. It won't work for 3 inputs simultaneously. I didn't realise that's what you wanted. If you want arbitrary number of inputs, you could try this: alltimes = input("Enter times in HH:MM\n").split() for time in alltimes: hour, min = [int(i) for i in time.split(":")] print(hour, "hours and", min, "minutes")
6th May 2020, 11:12 AM
Kishalaya Saha
Kishalaya Saha - avatar
+ 2
Thanks for this
6th May 2020, 8:26 AM
Mohan Raj Murugan
Mohan Raj Murugan - avatar
+ 1
time = input("Enter time in HH:MM\n") hour, min = [int(i) for i in time.split(":")] print("It is", hour, "hours and", min, "minutes") # time.split(":") splits the time into two parts, HH and MM. Then those two parts are converted into integers and then assigned to the variables hour and min.
6th May 2020, 7:04 AM
Kishalaya Saha
Kishalaya Saha - avatar
0
I tried but there is a value error
6th May 2020, 11:04 AM
Mohan Raj Murugan
Mohan Raj Murugan - avatar
0
The input was 10:00 9:55 10:02
6th May 2020, 11:05 AM
Mohan Raj Murugan
Mohan Raj Murugan - avatar