Unit 1 EXERCISES

 

Directions:  Create a Python Program  using the information given in the following problems. Make sure your output matches the example for each exercise

 

Saving Form Files to Disk or Uploading:  Class Names using this name convention.  The first problem below you will save as U1EX2.  Meaning, Unit 1 Exercise 2.

 

Make sure you have typed your name and unit/exercise like in a comment section like:

#Your Name

#U1EX2

 

your programmig stuff

 

 

 

Exercises

 

 

1.  Write a program to help you budget your fuel expenses. Enter a value for the number of miles you drive in one month, and another for the miles per gallon (MPG) your car gets. Assuming gas costs $3.35 a gallon, calculate your monthly fuel costs.

 

Enter monthly mileage: 1500

 

Enter MPG: 30

 

You spend $167.50 a month on gas

 

2.  Write a program that accepts two real numbers and prints out their sum, difference, product and quotient to 2 decimal places.

 

Enter a number: 4.8

 

Enter a number: 1.2

 

Sum = 6.00

 

Difference = 3.60

 

Product=5.76

 

Quotient=4.00

 

3.  a) Write a program that reads the price of a hamburger and the number of hamburgers bought. Print out the cost, in dollars and cents, of the purchased hamburgers. Use appropriate variable names to represent the values assigned to the variables:

 

Enter price of hamburgers: 0.59

 

Enter number of hamburgers: 10

 

The cost of hamburgers is $5.90

 

b) Edit the program to include calculation of a 6% sales tax:

 

Enter price of hamburgers: 0.59

 

Enter number of hamburgers: 10

 

The cost of hamburgers is $5.90

 

Sales tax is $0.35

 

Total cost of hamburgers is $6.25

 

 

4. Write a program to produce the following table using integers:

 

Enter an integer: 11

Enter an integer: 3

 

11 + 3 = 14

11 - 3 = 8

11 * 3 = 33

11 div 3 = 3

11 mod 3 = 2

 

5.    Write a program that allows a person to enter his or her weight in pounds and height in inches and then calculates the ratio of pounds per inch:

 

Enter height in inches: 74

Enter weight in pounds: 202

 

Pounds per inch = 2.73

 

6.    a) Parking tickets at the University of Delaware cost $22.75 each.

Write a program which uses a constant named Fine to calculate how much money you owe the parking department:

 

(Hint:  To put a constant into a program type  Const Fine=22.75 at the top of the code window.)

 

How many tickets do you have? 8

You owe $ 182.00

 

b) U. of S. has a new payment policy which allows you to pay $15.00 a week to the parking department until your fines have been paid. The cost per ticket, however, has risen to $27.55. Edit your program to tell you how many weeks it will take to pay your fine:

 

How many tickets do you have? 8

You owe $ 220.40

It will take 14.69 weeks to pay your fine.

 

7.    a) The area of a triangle is equal to one half the base times the height. Write a program that reads the base and height of a triangle in centime­ters and then writes the area using formatted output:

 

Enter the base in centimeters: 21

Enter the height in centimeters: 43

 

The area is 451.50 square centimeters.

 

b) There are 2.54 centimeters in an inch. Expand your program to also give the area in square inches. (Remember to convert centimeters to inches before finding the area.)

 

Enter the base in centimeters: 21

Enter the height in centimeters: 43

 

The area is 451.50 square centimeters

or 69.98 square inches.

 

8.    Sheila runs a pool service that charges by the square foot of pool serviced. Write a program that allows the user to enter the length and width of the pool and calculates the total cost. Use a constant to represent the cost per square foot, $0.17:

 

Enter the length of the pool: 25

Enter the width of pool: 15

 

The area to be serviced is 375.00 square feet. This job will cost $63.75

 

9.    a) Pizza contains 355 calories per slice. Jogging burns off 240 calories

per hour. Write a program to calculate how long, in hours and minutes,

you would have to jog to burn off the pizza that you eat:

 

How many slices of pizza? 3

You will have to jog 4.44 hours

 

b) Sushi only contains 120 calories per piece. Edit your program so that its output looks like this:

 

How many pieces of sushi? 3

You will have to jog 1.50 hours

 

10.  a) Amy's Garden Emporium must ship an order of flower pots to Duluth. A big box holds 4 pots and a small box 1 pot. Write a program to ship the order using the least number of boxes:  (Hint: You Need Div and Mod)

 

How many flower pots to be shipped? 26

 

You will need:                   6 big boxes

                                       2 small boxes

 

b) Amy's head shipping clerk has ordered another size box that can hold 9 pots. Edit your program to use all three sizes of boxes:

 

How many flower pots to be shipped? 88

 

You will need:                   9 large boxes

                                       1 big boxes

                                       3 small boxes

 

11.   Write a program to print the coins necessary to return change to a customer after a purchase. The change can be made up of the following coins: quarters, dimes, nickels and pennies. Your may assume that the amount of change is less than $1.00. Your program should use the minimum number of coins needed.

      (Hint: You Need Div and Mod)

 

Enter amount of change in cents: 69

 

Change:

     Quarters: 2

     Dimes: 1

     Nickels: 1

     Pennies: 4

 

12.  Professional athletes have succeeded in making staggering sums of money through careful negotiations. Of course, the real winner is the Internal Revenue Service, which does not negotiate at all. Write a program which asks for a player's earnings and then prints the take­home pay and taxes assuming the tax rate for that income bracket is 44%:

 

What are the player's earnings? 150000.0

The player keeps $84000.00

The player pays $66000.00 in taxes.