I was trying to reproduce the following entry in Python: 05 08:12:23
.
I did it as follows:
day, hour, minute, second = map (int, input (). Split (':'))
Notice how there is a space after day
and the split ()
I put to separate the numbers with ':'
. How would I go about reading the day on the same input? Is there a better way to do this than what I’m trying to do?
The following error ends:
day, hour, minute, second = map (int, input (). split (':'))
ValueError: invalid literal for int () with base 10: ’05 08 ‘
Advertisement
Answer
You have two different separators on the same line: space and colon. You have to divide the input in two steps:
day, clock = input().split() hour, minute, second = clock.split(':')
This leaves you with four strings, but you already know how to convert those. :-)