Exercises Set 2 – Unit 1 September12th, 2016
Simple exercises designed to get students familiar with the python environment. Python covered:
- Int, float, string variables
- input( )
- +, -, *, **, /, //.
- int(x), float(y), str(s)
Create Python programs to do the following:
Remember to analyze the question: find out which is the input, storage, process and output.
- The volume of a sphere with radius r is 4/3r3 . What is the volume of a sphere with radius 5?
Save as introEx1.py
- Suppose the cover price of a book is $24.95, but bookstores get a 40% discount. Shipping costs
$3 for the first copy and 75 cents for each additional copy. Display the total wholesale cost for
60 copies? Ask the user for the number of books and display the total cost for that number of copies.
Save as introEx2.py
- I leave my house at 6:52 am and run some distance at an easy pace (6:15 per km), then some distance attempo (5:32 per km). Ask how many km I run at an easy pace and how many at tempo. Calculate the time do I get home for breakfast? Save as introEx3.py
Example:
How many km you run at an easy pace: 1
How many km you run at tempo: 2
If you leave house at 6:52am you will be home at 7:09am
- Gets the user’s first and last name and outputs them in reverse order with a comma between them.
Save as introEx4.py
- Gets the coordinates for two points from the user and computes the distance.
Bonus: Round your answer to two decimal places. Save as introEx5.py
- At Jenny’s birthday party she orders a 32 piece pizza. Have the user (probably Jenny) enter the number of people at the party that will be eating pizza and output the number of slices each one gets. As you know the pizza might not divide evenly. There are two ways to handle this. The first is to ignore the extra pieces and give everyone the same amount. The second way is to cut up the extra pieces so that everyone gets the same amount.
Save as introEx6.py
Your program must output both options. For example:
*hint* use what you know of how Python divides integers and floats
Number of guests: 10
Option 1: 3 slices each, 2 left over
Option 2: 3.2 slices each
- Write a program that asks for a person’s year of birth and outputs their age in the current year. Write the program to work for whatever the current year happens to be. Save as introEx7.py
- Write a program reads in four numbers and then outputs the four numbers all on one line. Output on a second line the product of the same four numbers.
Save as introEx8.py
After completing all the Exercises, create a folder named:
LastnameF_Unit1 and be ready to drop it off on