IT 116: Introduction to Scripting
Homework 4
Due
Sunday, February 18th 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
- Exoplanets are planets that orbit stars other than
the sun
- Starting in the 1990s many exoplanets have been
discovered
- There are many different kinds of exoplanets, but
astronomers assign them into categories based on their size
relative to Earth
- Write a script that will take a multiple of the size
of the Earth and return the type for that size
- The type of exoplanet is given by the following
table
Type | Size Relative to Earth |
Terrestrial | <= 1.25 Earths |
Super-Earth | <= 2 Earths |
Neptune-like | <= 6 Earths |
Gas Giant | > 6 Earths |
Output
- The output should look something like this
Earths: 2
Super-Earth
- 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 diameter and gives this value to the variable
diameter.
Convert this value to an decimal using float()
.
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 diameter is less than or
equal to 1.25.
Inside this if
clause, assign type
the value "Terrestrial".
Outside this if
statement, print the value of
type.
Run the script.
Fix any errors you find.
-
Add an
elif
clause under the if
statement
that will run if the value of diameter is
less than or equal to 2.
Inside this clause set the value of type
to "Super-Earth".
Run the script.
Fix any errors you find.
-
Repeat the above step for the type "Neptune-like".
-
Add an
else
clause that sets the value of
type to "Gas Gian".
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 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
Earths: 2
Super-Earth
- 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.