## Programming Exercises

1. Feet to Inches

One foot equals 12 inches. Write a function named f eet_to_inches that accepts a number of feet as an argument, and returns the number of inches in that many feet. Use the function in a program that prompts the user to enter a number of feet and then displays the number of inches in that many feet.

2. Math Quiz

Write a program that gives simple math quizzes. The program should display two random numbers that are to be added, such as: 247 + 129

The program should allow the student to enter the answer. If the answer is correct, a message of congratulations should be displayed. If the answer is incorrect, a message showing the correct answer should be displayed.

### 3. Maximum of Two Values

Write a function named maximum that accepts two integer values as arguments and rerurns the value that is the greater of the two. For example, if 7 and 12 are passed as arguments to the function, the function should return 12. Use the function in a program that prompts the user to enter two integer values. The program should display rhe value that is the greater of the two.

4. Falling Distance

The following formula can be used to determine the distance an object falls due to gravity in a specific time period, starting from rest:

J=yigt2

The variables in the formula are as follows: d is the distance in meters, g is 9.8, and t is rhe amount of time in seconds, that the object has been falling.

Write a function named falling_distance that accepts an object's falling time in seconds as an argument. The function should return the distance in meters that the object has fallen during that time interval. Write a program that calls the function in a loop that passes the values 1 through 10 as arguments and displays the return value.

### 5. Kinetic Energy

In physics, an object that is in motion is said to have kinetic energy. The following formula can be used to determine a moving object's kinetic energy:

The variables in the formula are as follows: KE is the kinetic energy in joules, m is the object's mass in kilograms, and v is the object's velocity in meters per second.

Write a function named kinetic_energy that accepts an object's mass in kilograms and velocity in meters per second as arguments. The function should return the amount of kinetic energy that the object has. Write a program that asks the user to enter values for mass and velocity, and then calls the kinetic_energy function to get the object's kinetic energy.

222 Chapter 6 Value-Returning Functions and Modules 6. Test Average and Grade

Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and rhe average test score. Write rhe following functions in the program:

• calcaverage— This function should accept five test scores as arguments and return the average of the scores.

• deter mi ne_grade— This function should accept a test score as an argument and return a letter grade for the score, based on the following grading scale:

Score |
Letter Grade |

## Post a comment