Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Part 1: Write Python statements

For the tasks 1- 4 do NOT execute Python software and try to write the
answers for the following problem below.

Create the new Word document and name it YourName_Lab5A.docx , place


your answers in it and finally upload to Wikamp - Exercises Lab 5.

1. Using Python's Math functions write valid statements to determine:

a) the square root of 6.37


b) the absolute value of a2 - b2
c) the value of e raised to the 3rd power

2. Write a Python general-purpose function named findAbs( ) that accepts a float number
passed to it, computes its absolute value, and displays the absolute value.

Hint: You don’t need to write the full program here!

3. Write Python function header for the following description:


A general-purpose function is named check() and has three parameters. The first
parameter should accept an integer number, the second parameter a floating-point
number, and the third parameter a floating-point number. The function returns no value.

Hint: You don’t need to write the full program here!

4. Write Python function header for the following description:


A general-purpose function named mult( ) accepts two floating-point numbers as
parameters, multiplies these two numbers, and returns the result.

Hint: You don’t need to write the full program here!


Part 2: Practical Examples

For the tasks 5-11 solve the problems executing Python programs (use
Spyder-Anaconda environment).

Create another Word document and name it YourName_Lab5B.docx.

For each solution do the print screen of your full display (incl. the code and
output windows) and paste the pictures in the document. Upload it to Wikamp
- Exercises Lab 5.

5. Write a program that determines the time it takes a ball to hit the ground after it has
been dropped from an 800-foot tower. The mathematical formula to calculate the time, in
seconds, that it takes to fall a given distance, in feet, is:
time = sqrt (2 * distance / g)
where g is the gravitational constant equal to 32.2 ft/sec^2.

6. A model of worldwide population, in billions of people, after the year 2000 is given by
the equation
population = 6.0 e 0.02 [Year – 2000]
Using this formula, write a Python program to estimate the worldwide population in the
year 2021 and in the 2030.

7. Create a series of N random numbers using Python's library random.randrange( ) to


generate a series of 10 random numbers from range 1 to 100.

8. According to Plato, a man should marry a woman whose age is half his age plus seven
years. Write a program that requests a man’s age as input and gives the ideal age of his
wife. Use two separate functions for input and output.

9. To determine the number of square centimeters of tin needed to make a tin can, add the
square of the radius of the can to the product of the radius and height of the can, and then
multiply this sum by 6.283.
Write a program that requests the radius and height of a tin can in centimeters as input
and displays the number of square centimeters required to make the can. Use two
separate functions for input and output.

10. The original cost of airmail letters was 5 cents for the first ounce and 10 cents for each
additional ounce. Write a program to compute the cost of a letter whose weight is given by
the user. Use at least two functions.
Hint: Use the function ceil( ). Test the program with weights 4, 1, 2.5, 0.5 ounce.
11. A fast-food vendor sells pizza slices ($1.25), fries ($1.00), and soft drinks ($0.75).
Write a program to compute a customer’s bill. The program should request the quantity of
each item ordered in a first function, calculate the total cost with a second, and use the
third to display an itemized bill. The sample output is presented below:

Number of pizza slices: 1


Total for pizza slices: 1.25$
Number of fry portions: 0
Total for fry portions : 0$
Number of soft drinks: 0
Total for soft drinks: 0$
Total bill: 1.25$

You might also like