Apr-08-2020, 11:58 AM
I'm getting ValueError:time data ' ' does not match format '%H:%M'
for the following text file with text message
for the following text file with text message
Quote:Cricket, a bat-and-ball park game played between two teams of eleven park
players on a field at the park center of which is a 20-metre (22-yard) pitch with
a wicket at each end, each park comprising two bails balanced on three stumps.
The batting park scores runs by striking the ball bowled at the park wicket with
the park bat, while the bowling and park fielding side tries to prevent this and
dismiss each park player (so they are "out"). Means of park include being
bowled, when the ball hits the park and dislodges the bails, and by the fielding
side park the ball after it is hit by the bat, but before it hits the park. When ten
park have been dismissed, the innings ends and the teams park roles.
from datetime import datetime def SecretCode(file): lines = file.readlines() NumOfLines = str(len(lines)) getTime = '' if (len(NumOfLines) > 2): getTime = NumOfLines[:2]+":"+NumOfLines[2:] elif(len(NumOfLines) == 2): getTime = NumOfLines[:2]+":"+"00" words = [word for line in lines for word in line.split()] Meeting_place = max(words, key=words.count)+" Street" d = datetime.strptime(getTime, "%H:%M") Meeting_time = d.strftime("%I:%M %p") print("Meeting time:{}".format(Meeting_time)) print("Meeting place:{}".format(Meeting_place)) if __name__ == "__main__": fname = input() file = open(fname, "r") SecretCode(file)