[Type C]Q6. 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.

A function is a block of organized, reusable code that is used to perform a single, related action.

Functions provide better modularity for your application and a high degree of code reusing.

Syntax

def functionname( parameters ):
   "function_docstring"
   function_suite
   return [expression]

Program code:

Clear Doubts with Computer Tutor
In case you’re facing problems in understanding concepts, writing programs, solving questions, want to learn fun facts | tips | tricks or absolutely anything around computer science, feel free to join CTs learner-teacher community: students.computertutor.in

Output:

Enter feet : 10
Number of inches : 120

Three functions are defined for conversion of feet to inches, Taking input of feet from user and displaying function which displays the accurate inches after conversion respectively.

The user input is passed as argument to conversion function and result of conversion is then displayed.

Basic python functionality is demonstrated in above program.

To view all the lessons in chapter 1: http://computertutor.in/class-12-computer-science/chapter-1/

To view entire class 12 computer science study material: http://computertutor.in/resources/

You cannot copy content of this page