I’m working on a project about bus times on Telegram, but Python prints the hour which ends with 0
without the 0
, e.g 10.10
becomes 10.1
.
if len(htp) > 0: # if the list contains at least one time
alert3 = "I prossimi pullman sono alle: "
orari_ufficiosi = []
for rfd in htp: # for each timetable
if allhd[allh.index(str(rfd))] != "0": # if the destination stop has that line
orari_ufficiosi.append(rfd)
bot.api.call('sendMessage', {
'chat_id': chat_id,
'text': alert3 + str(",n ".join(map(str,orari_ufficiosi)))
})
The problem can be seen here.
2
Answers
Check this code:
Sample output:
I tried this I guess
format(a,'.2f')
will be correct one for your need or you select from below. Here’s an example how to use:But see to it that it will be a string and I guess you will be sending this as a Telegram message so this will work for you.