#๐Ÿ”’ Zero padding doesn't work

47 messages ยท Page 1 of 1 (latest)

tepid fulcrumBOT
#

@winged hatch

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

winged hatch
tepid fulcrumBOT
winged hatch
#

elif AMPM.upper() == "PM" and alarm_time_hour != 12:
alarm_time_hour += 12
return f"{alarm_time_hour:02}:{alarm_time_minute:02}:00"

#

I have no idea why it doesn't want to zero pad the numbers

winged hatch
#

It should output the time as a string that I then compare with the string from the now function of the datetime module

#

However if I input the hour as 3

#

for example

soft ridge
#

and ampm as pm im assume pithink

winged hatch
#

it should be 03:00:00

#

but despite formatting it to be zero padded it still returns 3:00:00 for some reason I don't quite understand

soft ridge
#

where exactly are u displaying this

winged hatch
#

displaying what

#

I'm not displaying the alarm time

#

I'm just gonna compare it with the current time later in the code

soft ridge
#

now im just confused

#
PS C:\Users\Dagger> py -c 'print(f\"{4:02}:{0:02}\")'
04:00
PS C:\Users\Dagger>

fyi u did the padding part right

#

i just want to know where u seeing the 3:00:00

winged hatch
winged hatch
soft ridge
winged hatch
#

ok one sec

#

the second line is the alarm time

soft ridge
# winged hatch

thats not all the terminal output, thats just the 2 print at the end pithink

winged hatch
#

my bad

#

these are the first inputs

soft ridge
#
    AMPM = input("AM or PM?: ")
    while AMPM.upper() not in ["AM", "PM"]:
        AMPM = input("Please select AM or PM: ")

    if AMPM.upper() == "AM":
        return f"{alarm_time_hour}:{alarm_time_minute}:00"
    
    elif AMPM.upper() == "PM" and alarm_time_hour != 12:
        alarm_time_hour += 12
        return f"{alarm_time_hour:02}:{alarm_time_minute:02}:00"
winged hatch
#

is just loops over the alarm time and the current time

#

ohhh

#

I just saw it

#

I forgot to add the zero padding to the AM if clause

soft ridge
winged hatch
#

this is super embarassing lol

#

I knew it was gonna be a stupid syntax error on my part

soft ridge
#

not even syntax error just missusing ur own code/programn

winged hatch
#

well,thanks for sticking with me and sorry for wasting your time

soft ridge
soft ridge
#

go have ur fun

winged hatch
#

thanks

#

!close

tepid fulcrumBOT
#
Python help channel closed with !close

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.