IT 116: Introduction to Scripting
Homework 7

Due

Sunday, March 30th at 11:59 PM

What You Need to Do

Setup On Your Machine

Specification

Functions

get_int


inches_to_centimeters_table


inches_to_centimeters


centimeters_to_inches_table


centimeters_to_inches

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 inches_to_centimeters_table.
    Replace it with a statement that prints the labels "Inches" and "Centimeters".
    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 inches 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 inches.
    Run the script.
    Fix any errors you find.
  5. Add a second argument to the print statement in inches_to_centimeters_table.
    This argument will be a call to the function inches_to_centimeters with inches as the argument.
    Remove the pass statement from inches_to_centimeters.
    Replace it with a statement that returns the parameter inches.
    Run the script.
    You should see two values for inches on each line.
    Fix any errors you find.
  6. Remove the return statement in inches_to_centimeters.
    Replace it with an assignment statement that gives the variable cm the converted value of inches.
    You will do this using the formula
    cm = inches * 2.54
    Turn the value of cm into an integer with an assignment statement using round.
    Return the value of cm.
    Run the script.
    You should see both the inches and cm values on the same line.
    Fix any errors you find.
  7. Now you have to make sure the cm values align with the "Centimeters" label.
    This can be done using the escape sequence for the tab character, \t.
    Replace the space between "Inches" and "Centimeters" in the label with \t.
    Now we need to print inches and cm 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 inches and cm.
    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 function making appropriate changes.
    Use the conversion formula
    inches = centimeters * 0.39370079

Testing on Your Machine

Copy the Script to Unix

Testing the Script on Unix (Optional)

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