+ 1
Python | Time matches
Hey! I want to print all the possible time matches in HH:MM format: 00:00 00:01 00:02 NN:NN 12:58 12:59 Help me, please!
8 Respostas
+ 3
f-Strings is a newer way of string formatting in python
i have written some string formatting demo some time ago:
https://code.sololearn.com/cgUSSCEyco53/?ref=app
here you can find a very detailed description of string formatting possibilities:
https://realpython.com/python-f-strings/
+ 2
You could use a nested loop.
• The outer loop iterates through the hours [0; 12]
• The inner loop iterates for each hour through the minutes [0; 59]
+ 1
I'm not sure if I got the question, but what works for example:
hour = 3
minute = 5
print(str(hour).zfill(2) + ":" + str(minute).zfill(2))
outputs:
03:05
+ 1
Martin Ed Yes, that's what I had in mind 😀
Nice formatting! 😀
+ 1
Martin Ed, that worked fine - just had to change 12 to 13 to get all the possible matches up to 12:59 (for i in range(13))!
Thanks a lot!
but, please, would you explain to me the print parameters you added:
f
{i:02d}
+ 1
i is the variable name 02d formats, for example i = 3 to 03 in the f-string
+ 1
Gotcha! Thanks a lot, guys!