During this activity, students should be able to:
Solve the following set of problems using Python 3. Run and test each of your programs to make sure they work as expected.
Five Star Video rents new videos for $3.00 a night, and oldies for $2.00 a night. Write a program called video.py
that the clerks at Five Star Video can use to calculate the total charge for a costumer’s video rentals. The program should prompt the user for the number of each type of video and output the total cost.
Example (user input is in blue):
Number of new videos to rent: 3 Number of old videos to rent: 5 Total charge for costumer's video rentals: $ 19
There are 1024 bytes in a kibibyte (KiB), and there are 1024 kibibytes in a mebibyte (MiB). Write a program called byte.py
that accepts a number of bytes as input and converts that value into mebibytes.
Example (user input is in blue):
Number of bytes: 4718592
4718592 is equal to 4.5 MiB.
An object’s momentum is its mass multiplied by its velocity. Write a program called momentum.py
that accepts an object’s mass (in kilograms) and velocity (in meters per second) as inputs and then outputs its momentum.
Example (user input is in blue):
Object's mass in kilograms: 4.6 Object's velocity in meters per second: 1.2 The object's momentum is: 5.52 kg m/s
The kinetic energy (\(\textit{KE}\;\)) of a moving object is given by the formula:
$$ \textit{KE} = \frac{1}{2} m v^2 $$
where \(m\) is the object’s mass and \(v\) is its velocity. Write a program called kinetic.py
that prints the object’s kinetic energy as well as its momentum (see the previous problem).
Example (user input is in blue):
Object's mass in kilograms: 4.6 Object's velocity in meters per second: 1.2 The object's kinetic energy is: 3.312 joules The object's momentum is: 5.52 kg m/s
Write a program called minutes.py
that calculates and prints the number of minutes in a year (assume that a year has 365.25 days).
light.py
that calculates and displays the value (in meters) of a light-year (assume that a year has 365.25 days).
In biology, the total population \(T\) based on a generation number can be calculated using this formula:
$$ T = IC^n $$Where \(I\) is the initial population, \(C\) is the number of offspring per parent, and \(n\) is the generation number.
Write a program called population.py
that takes \(I\), \(C\), and \(n\) as inputs and prints the corresponding total population.
Example (user input is in blue):
Initial population: 3 Number of offspring per parent: 5 Generation number: 10 Total population is 29296875
Write a program called nautical.py
that takes as input a number of kilometers and prints the corresponding number of nautical miles. Use the following approximations:
Example (user input is in blue):
Number of kilometers: 12.5
12.5 kilometers is equal to 6.75 nautical miles.
An employee’s total weekly pay equals the hourly wage multiplied by the total number of regular hours plus any overtime pay. Overtime pay equals the total overtime hours multiplied by 1.5 times the hourly wage. Write a program called wage.py
that takes as inputs the hourly wage, total regular hours, and total overtime hours and displays an employee’s total weekly pay.
Example (user input is in blue):
Hourly wage: 7.25 Total regular hours: 35.5 Total overtime hours: 5.5 Employee's total weekly pay is: $ 317.1875
Write a program called rain.py
that accepts as input the depth of rain (in inches) that has fallen over an acre of land. The program should calculate and print the water volume (in gallons) accumulated on that acre.
You will need to use the following conversion formulas:
Example (user input is in blue):
Depth of rain (in inches): 5.9
5.9 inches of rain over one acre of land
is equal to 160210.29684 gallons.
Problems taken from:
Kenneth Lambert.
Fundamentals of Python: From First Programs through Data Structures.
CENGAGE Learning, 2010.
p. 74.