[Type C] Python Revision Tour-1 – Chapter 1

|
Table of Contents

6. One foot equals 12 inches. Write a function that accepts a length written in feet as an argument and returns this length written in inches. Write a second function that asks the user for a number of feet and returns this value. Write a third function that accepts a number of inches and displays this to the screen. Use these three functions to write a program that asks the user for a number of feet and tells them the corresponding number of inches.

def feet_to_inches(feet):
    return feet * 12

def get_feet_from_user():
    return float(input("Enter length in feet: "))

def display_inches(inches):
    print("Length in inches:", inches)

# Example usage:
feet = get_feet_from_user()
inches = feet_to_inches(feet)
display_inches(inches)
Output
Enter length in feet: 5
Length in inches: 60.0
"Spread the light within, illuminate the hearts around you. Sharing is not just an action, but a sacred journey of connecting souls."~ Anonymous

Leave a Reply

Your email address will not be published. Required fields are marked *