Step Counter – creating functions

  Kiến thức lập trình

A pedometer treats walking 1 step as walking 2.5 feet. Define a function named feet_to_steps that takes a float as a parameter, representing the number of feet walked, and returns the number of steps walked as an integer by using int(). Then, write a main program that reads the number of feet walked as an input, calls function feet_to_steps() with the input as an argument, and outputs the number of steps returned from feet_to_steps().

Use floating-point arithmetic to perform the conversion.

Note: Converting a float to an integer may affect the result’s
accuracy.

if __name__ == "__main__":
    def feet_to_steps(feet_walked):
        steps = feet_walked / 2.5
        return round(steps)

    feet_walked = float(input())
    steps_walked = feet_to_steps(feet_walked)
    print(steps_walked)

New contributor

Jade Tinin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

2

LEAVE A COMMENT