IT 116: Introduction to Scripting
Homework 4
Due
Sunday, February 23rd at 11:59 PM
What You Need to Do
- Create the script hw4.py
- Make sure it obeys the rules in
Rules for Homework Scripts
- Move it to an an hw4
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 hw4.py
Specification
- Write a script that will turn a number read off
a machine into a letter quality grade
- The script will ask the user to enter the machine's
reading
- The script will turn that reading into a letter grade
- And print that grade
- The quality grades are given by the following table
Score Range | Quality Grade |
88 or above | A |
87 to 76 | B |
75 to 62 | C |
61 to 48 | D |
47 or below | F |
Output
- The output should look something like this
Score: 65
C
- The text in blue is what the
user enters
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
-
Write an assignment statement using the
input
function
that asks the user for the score and gives this value to the variable
score.
Convert this value to an integer.
Print the value.
Run the script.
Fix any errors you find.
-
Remove the
print
statement you wrote in the previous step.
Replace it with an if
statement that will run if
the value of score 88 or more.
Inside this if
clause, assign grade
the value "A".
Outside this if
statement, print the value of
grade.
Run the script.
Fix any errors you find.
-
Add an
elif
clause under the if
statement
that will run if the value of score is
greater than or equal to 76.
Inside this clause set the value of grade
to "B".
Run the script.
Fix any errors you find.
-
Repeat the above step for the grades "C" and "D".
-
Add an
else
clause that sets the value of
grade to "F".
Run the script.
Fix any errors you find.
Testing on Your Machine
- Open IDLE
- Use the Open command in IDLE to open hw4.py
- Run your script inside IDLE
- Your output should look something like this
Score: 65
C
- The text in blue is what you
enter at the command line
- You should test your script with the following values to make sure
your script works for all grades
88
87
76
75
62
61
48
47
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 hw4 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)
- Connect to pe15.cs.umb.edu
using an ssh client like putty.exe (Windows)
or ssh (Mac)
- Go to the directory for this exercise
cd it116/hw/hw4
- Run this script
python3 hw4.py
- You should see something like this
Score: 65
C
- The text in blue is what you
enter at the command line
Copyright © 2023 Glenn Hoffman. All rights reserved. May not be reproduced without permission.