[Python] Unsupported format string passed to NoneType.__format__

Discussão em 'Python' iniciado por Stack, Outubro 2, 2024.

  1. Stack

    Stack Membro Participativo

    The initial problem I started with is:


    Write a function so that the main program below can be replaced by the simpler code that calls function mph_and_minutes_to_miles().

    miles_per_hour = float(input())
    minutes_traveled = float(input())
    hours_traveled = minutes_traveled / 60.0
    miles_traveled = hours_traveled * miles_per_hour

    print('Miles: {:f}'.format(miles_traveled))


    Sample output with inputs: 70.0 100.0
    Miles: 116.666667
    ​

    The code I have written for it so far is:

    def mph_and_minutes_to_miles(miles_per_hour,minutes_traveled):
    hours_traveled=minutes_traveled/60.0
    miles_traveled=hours_traveled*miles_per_hour
    print('Miles: {:f}' .format(miles_traveled))
    miles_per_hour = float(input())
    minutes_traveled = float(input())

    print('Miles: {:f}'.format(mph_and_minutes_to_miles(miles_per_hour, minutes_traveled)))


    The error message it produces is:

    Exited with return code 1.
    Traceback (most recent call last):
    File "main.py", line 8, in <module>
    print('Miles: {:f}'.format(mph_and_minutes_to_miles(miles_per_hour, minutes_traveled)))
    TypeError: unsupported format string passed to NoneType.__format__


    After reviewing the code a few times I still can not seem to figure out how to rectify it.

    Continue reading...

Compartilhe esta Página