This activity provides some practice and experience using variables and doing calculations.

Turn In: At least five of the following files

Create the filename listed below and complete the task(s) that is indicated. Be sure to run your program and make sure that it runs with no errors and produces the correct results. Submit the completed files to your instructor.

The top of each file should have a comment section that includes the name of the file, your name, the date your program was completed, and a brief description of what it does.

Each of the program files below should have three sections ... variable assignment, calculation, and display the results. When asked to do multiple calculations, put the second calculation after the first one.

Item 1 is completed for you below (you still have to create the file, put the statements in, and test the results).

OneSide = 14 Perimeter = OneSide * 4 print("The perimeter of a square with the sides of ", OneSide, " inches is ", Perimeter, " inches")OneSide = 8 Perimeter = OneSide * 4 print("The perimeter of a square with the sides of ", OneSide, " inches is ", Perimeter, " inches")

1. SquarePerimeter.py -- calculate the perimeter of a square with the side of 14 inches. Create a variable named OneSide and assign 14 to that variable. Perimeter of a square is found by multiplying distance of one side of the square by 4. Create a variable named Perimeter and write the calculation with the OneSide variable and place the results into the Perimeter variable. Display a message like "The perimeter of a square with the sides of 14 inches is 56 inches". Repeat this for a square with the sides of 8 inches.

2. SquareArea.py -- calculate the area of a square with the side of 14 inches. Create a variable named OneSide and assign 14 to that variable. Area of a square is found by squaring the side the square. Create a variable named Area and write the calculation with the OneSide variable and place the results into the Area variable. Display a message like "The area of a square with the sides of 14 inches is 196 inches". Repeat this for a square with the sides of 8 inches.

3. Celsius2Fahren.py -- this program will convert a temperature in Celsius to the equivalent temperature in Fahrenheit. Assign 10 the variable named Celsius. Then calculate the variable Fahren by taking the Celsius value and multiple it by 9 then divide by 5 then add 32. Display the results ... "10 Celsius = 50 Fahrenheit". Do a second calculation using the celsius temperature of 25.

4. FiveSidePerimeter.py -- find the perimeter (distance around) of a five sided object where the five sides are 23, 47, 29, 50, and 36. Create 5 variables to store those values. The variable named Perimeter should contain your answer. Display the result of your calculations nicely formatted. Calculate a second time changing the 23 to a 32 and the 50 to 59.

5. Speedometer.py -- this program will convert a miles per hour value to kilometers per hour. Your display will look like "0 mph = 0 km/h". Multiply the mile per hour by 1.609 to get the corresponding Kilometers per hour. Do three calculations and displays using the numbers 35, 55, and 70. Create a variable for miles per hour and another variable for kilometers per hour.

6. MPG.py -- Miles per gallon is used to determine how efficient your car is running. Miles per gallon is calculated by subtracting the starting odometer value from the ending odometer value then dividing by the number of gallons used. Calculate miles per gallon if the starting odometer reading is 5185 and the ending odometer reading is 5568 with 9.4 gallons of gas used. Also, calculate this when starting at 356729 ending at 356973 and using 6.2 gallons of gas.

7. WeekendDaysLeft.py -- If you live to 90, how many weekend days (Saturday and Sunday) do you have left to live? Start by assigning the variable Age with your current age. Next, calculate how many years between now and when you are 90 and start that answer in the variable YearsLeft. Next multiply the YearsLeft by 52 for the number of weeks in one year and multiply that by that by 2 for the two days of the weekend per week. Store that answer in the variable DaysLeft. Also calculate this for someone who is 68 years old. Display the results of your calculations (and make the most of the weekend days you have left).

8. Pythagorean.py -- Use three variables to represent the three sides of a right triangle. Set the variables for the smaller two sides of the triangle then calculate the longest side of the triangle (using Pythagorean's Theorem). Use 2 and 3 for the first two smaller sides and calculate the longest side. Do another calculation with the smaller sides of 5 and 12 then calculate the longest side.

Copyright © 2021 Eric Schumm. Permission granted to freely use this in your classroom.