pythonprintingformat

How to solve: ValueError: Invalid format specifier?


h=1
m=1
s=30
k=5
ks = ((h * 60) + m + (s / 60)) / k
s=(ks - int(ks)) * 0.6
print(f'0{ks:.0f}:{s:.2f:.02}') 

I am trying run the code, but i recieve the error: ValueError: Invalid format specifier


Solution

  • ValueError: Invalid format specifier '.2f:.02' for object of type 'float'
    

    This is the full error, simply you can't use 2f:.02 as specifier in brackets.

    >>> print(f'0{ks:.0f}:{s:.2f}')
    012:0.18
    

    This is a sample output changing the specifier in brackets.