IT 116: Introduction to Scripting
Homework 6

Due

Sunday, March 3rd at 11:59 PM

What You Need to Do

Setup On Your Machine

Specification

Functions

print_table


print_header


print_line

Test Code

Output

Suggestions


  1. Copy only the function headers for the three functions listed above into your script file.
    Under each header, write pass.
    pass is a special Python statement that does nothing.
    You use it in situations like this.
    Make sure each pass statement is indented.
    Run the script.
    Fix any errors you find.
  2. Remove the pass statement from print_table.
    Print the parameters min and max.
    Copy the test code above to the bottom of your script.
    Run the script.
    Fix any errors you find.
  3. Replace the print statement in print_table with a call to print_header.
    Remove the pass statement from print_header.
    Add a print statement for the labels at the top of the table.
    You will need to put a Tab character between the two words so everything will line up.
    You do this with an escape sequence.
    Add another print statement for the line of dashes.
    Run the script.
    After the input prompts you should see
    Kilometers	Miles
    -------------------
    Fix any errors you find.
  4. In print_table add a for loop using the loop variable km and the range function.
    Range should produce all the values between min and max.
    Think carefully when choosing the arguments for range. Inside the loop print the value of km.
    Run the script.
    Fix any errors you find.
  5. In print_table replace the print statement inside the for loop with a call to print_line.
    Inside print_line remove the pass statement.
    Replace it with a statement that prints the value of the parameter km.
    Run the script.
    The output should be the same as above but now it comes from print_line.
    Fix any errors you find.
  6. Remove the print statement from print_line.
    In it's place you need to write an assignment statement that sets the value of the local variable miles.
    Use the same formula you used in homework 5 to get the value for miles.
    Print the values of both km and miles.
    Run the script.
    Fix any errors you find.
  7. Change the print statement in print_line so it prints a single string with a Tab character between km and miles.
    You will have to use the conversion function str to change both variables to a string.
    The values should line up with the labels for each column.
    Run the script.
    Fix any errors you find.

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.