IT 116: Introduction to Scripting
Homework 7

Due

Sunday, October 27th at 11:59 PM

What You Need to Do

Setup On Your Machine

Specification

Specification

Functions

get_int


fahrenheit_to_celsius_table

fahrenheit_to_celsius

celsius_to_fahrenheit_table

celsius_to_fahrenheit

Test Code

Output

Suggestions


  1. Copy only the function headers for the five functions listed above into your script file.
    Under each header, write pass.
    Make sure this statement is indented.
    Run the script.
    Fix any errors you find.
  2. Remove the pass statement from get_int.
    Replace it with an assignment statement that uses input to give the variable number a value.
    Use the parameter prompt as the argument to input.
    Use an assignment statement to convert number into an integer.
    Return number.
    Copy the test code to the bottom of the script file.
    Comment out all but the first two lines of the test code.
    Run the script.
    Fix any errors you find.
  3. Remove the pass statement from fahrenheit_to_celsius_table.
    Replace it with a statement that prints the labels "Fahrenheit" and "Celsius".
    Then write a statement that prints a line of dashes, -.
    Uncomment the next two lines in the test code.
    Run the script.
    Fix any errors you find.
  4. Write a for loop that gives the loop variable fahr values from min to max.
    You will have to use range to do this, and be careful about the 2nd argument.
    Inside the loop print the value of fahr.
    Run the script.
    Fix any errors you find.
  5. Add a second argument to the print statement in fahrenheit_to_celsius_table.
    This argument will be a call to the function fahrenheit_to_celsius with fahr as the argument.
    Remove the pass statement from fahrenheit_to_celsius.
    Replace it with a statement that returns the parameter fahr.
    Run the script.
    You should see two values for fahr on each line.
    Fix any errors you find.
  6. Remove the return statement in fahrenheit_to_celsius.
    Replace it with an assignment statement that gives the variable celsius the converted value of fahr.
    You will do this using the formula
    celsius = (fahr - 32) * 5/9
    Turn the value of celsius into an integer with an assignment statement using round.
    Return the value of celsius.
    Run the script.
    You should see both the fahr and celsius values on the same line.
    Fix any errors you find.
  7. Now you have to make sure the celsius values align with the "Celsius" label.
    This can be done using the escape sequence for the tab character, \t.
    Replace the space between "Fahrenheit" and "Celsius" in the label with \t.
    Now we need to print fahr and celsius with \t in between.
    To make this work we will need to concatenate the three values.
    But numbers cannot be concatenated with strings.
    So we have to run the str string conversion function on both fahr and celsius.
    Then we can use concatenation to put \t between them.
    Run the script.
    Fix any errors you find.
  8. Repeat steps 3 - 7 for the last two functions making appropriate changes.
    Use the conversion formula
    fahr = celsius * 9/5 + 32

Testing on Your Machine

Copy the Script to Unix

Testing the Script on Unix (Optional)

Copyright © 2022 Glenn Hoffman. All rights reserved. May not be reproduced without permission.