0
How take user input in time format HH:MM in python language
Help
5 ответов
+ 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")
+ 2
Thanks for this
+ 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.
0
I tried but there is a value error
0
The input was
10:00 9:55 10:02