Python 1: Introduction to Python
Homework 6

Due

Sunday

Deliverables

There is one deliverable for this assignment

Specification

Your script must print a Celsius to Fahrenheit conversion table and between a minimum and maximum values, and a Fahrenheit to Celsius conversion also between a minimum and maximum values.

The tables should have the same format as in homework 4.

The code must have four functions

celsius_to_fahrenheit

This function must have the following header
def celsius_to_fahrenheit(celsius):
This function takes a Celsius value as its parameter and calculates the corresponding Fahrenheit value.

The Fahrenheit value must be an integer.

The function returns the Fahrenheit value.

print_celsius_to_fahrenheit_conversion_table

This function must have the following header
def print_celsius_to_fahrenheit_conversion_table(min, max):
This function will print a table of Celsius temperatures and their corresponding Fahrenheit values.

It must print the column labels "Celsius" and "Fahrenheit".

It then prints out a line of dashes, -.

This must be followed by a loop between the minimum and maximum values.

Each pass through the loop should print a Celsius value and the corresponding Fahrenheit value.

The temperature values should line up with the labels at the top of the table.

fahrenheit_to_celsius

This function must have the following header
def fahrenheit_to_celsius(fahrenheit):
This function takes a Fahrenheit value as its parameter and calculates the corresponding Celsius value.

The Celsius value must be an integer.

The function returns the Celsius value.

print_fahrenheit_to_celsius_conversion_table

This function must have the following header
print_fahrenheit_to_celsius_conversion_table(min, max):
This function will print a table of Fahrenheit temperatures and their corresponding Fahrenheit values.

It must print the column labels "Fahrenheit" and "Celsius".

It then prints out a line of dashes, -.

This must be followed by a loop between the minimum and maximum values.

Each pass through the loop should print a Fahrenheit value and the corresponding Celsius value.

The temperature values should line up with the labels at the top of the table.

Test Code

The script must contain the following test code at the bottom of the file
min_celsius = int(input("Minimum Celsius temperature: "))
max_celsius = int(input("Maximum Celsius temperature: "))
print()
print_celsius_to_fahrenheit_conversion_table(min_celsius, max_celsius)
print()
min_fahrenheit = int(input("Minimum Fahrenheit temperature: "))
max_fahrenheit = int(input("Maximum Fahrenheit temperature: "))
print()
print_fahrenheit_to_celsius_conversion_table(min_fahrenheit, max_fahrenheit)

Suggestions

Write this script in stages, testing your script at each step
  1. Create the script and paste into it the test code above.
    Create the headers for each of the four function.
    For the body of each of the functions, add the single Python statement pass.
    Running the script should only ask you for four values. Fix any errors you find.
  2. Remove the pass statement in celsius_to_fahrenheit.
    Replace it with code that calculates the Fahrenheit value for a Celsius temperature and assigns it to a variable.
    Add a statement that returns the Fahrenheit value.
    Add the following line to the test code
    print(celsius_to_fahrenheit(0))
    Run the script and fix any errors.
  3. Remove the test code above.
    Remove the pass statement from print_celsius_to_fahrenheit_conversion_table.
    Add a print statement to print the column labels.
    Add a print statement to print a line of dashes.
    Run the script and fix any errors.
  4. Add a loop that runs from the minimum to the maximum temperatures.
    Inside the loop, print the Celsius values.
    Run the script and fix any errors.
  5. Change the print statement inside the loop to print the Fahrenheit values along with the Celsius values. Run the script and fix any errors.
  6. Repeat the steps above with the other two functions.

Output

Your output should look like this

Minimum Celsius temperature: 0
Maximum Celsius temperature: 10
Celsius Fahrenheit
------------------
0       32
1       34
2       36
3       37
4       39
5       41
6       43
7       45
8       46
9       48
10      50

Minimum Fahrenheit temperature: 32
Maximum Fahrenheit temperature: 40
Fahrenheit  Celsius
-----------------------
32          0
33          1
34          1
35          2
36          2
37          3
38          3
39          4
40          4
The entries in blue are user input.