IT 116: Introduction to Scripting
Homework 6
Due
Sunday, October 13th at 11:59 PM
What You Need to Do
- Create the script hw6.py
- Make sure it obeys the rules in
Rules for Homework Scripts
- Move it to an an hw6
directory on pe15.cs.umb.edu
Setup On Your Machine
- Open a text editor.
I would suggest the text editor built into the program IDLE
.
- Save the file as hw6.py
Specification
Functions
print_table
print_header
- Header
def print_header():
- This function should print the labels "Celsius" and
"Fahrenheit"
- It should then print a line of dashes
print_line
- Header
def print_line(celsius):
- This function will print one line of the
conversion table
- It will convert the Celsius value into Fahrenheit
- Then it will print the Celsius and Fahrenheit values
- See the output below
Test Code
Output
Suggestions
- Write this script in stages
- Test your script at each step
- Print the steps below
- And check them off as you finish each one
-
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.
-
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.
-
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
Celsius Fahrenheit
-------------------
Fix any errors you find.
-
In print_table add a
for
loop
using the loop variable celsius 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 celsius.
Run the script.
Fix any errors you find.
-
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
celsius.
Run the script.
The output should be the same as above but now it comes from
print_line.
Fix any errors you find.
-
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 fahr.
Use the same formula you used in homework 5 to get the value for
fahr.
Print the values of both celsius and
fahr.
Run the script.
Fix any errors you find.
-
Change the
print
statement in print_line
so it prints a single string with a Tab character between
celsius and fahr.
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
- Open FileZilla and connect to
pe15.cs.umb.edu
- Go to your it116 directory
- Go to your hw directory
- Right-click in the whitespace inside the
hw directory
- Enter hw6 in the dialog box
- Click and drag your script from the bottom left panel
to the bottom right panel
Testing the Script on Unix (Optional)
Copyright © 2022 Glenn Hoffman. All rights reserved. May not be reproduced without permission.