IT 116: Introduction to Scripting
Homework 3
Due
Sunday, February 11th at 11:59 PM
What You Need to Do
- Create the script hw3.py
- Make sure it obeys the rules in
Rules for Homework Scripts
- Move it to an an hw3
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 hw3.py
Specification
- This program will convert miles into kilometers and
vice versa
- The program must prompt the user for a value in miles
- Then convert this value to kilometers
- And print the converted value
- The converted value must be an integer
- Then a blank line should be printed
- Now the program must prompt the user for a value in
kilometers
- This value must be converted to miles
- Then print the converted value
- Again the converted value must be a integer
- You convert miles to kilometers using the formula
km = miles * 1.609344
- You convert kilometers to miles using the formula
miles = km / 1.609344
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
-
Write an assignment statement which asks the user for a value in
miles and stores it in the variable
miles.
Convert the value of miles using to an
integer using int()
.
Write an assignment statement that calculates the kilometer value
and assigns it to the variable km.
Use the formula above and the value of the variable
miles.
Convert km to integer using
int()
.
Print the value of km.
Run the script to make sure it works properly.
A miles value of 5 should give a kilometers value of 8.
If it does not work, fix the problem.
-
Write an assignment statement which asks the user for a value in
kilometers and stores it in the variable
km.
Convert the value of km to an integer using
int()
.
Write an assignment statement that calculates the miles value
and assigns it to the variable miles.
Use the formula above and the value of the variable
km.
Convert miles to integer using
int()
.
Print miles.
Run the script to make sure it works properly.
A kilometers value of 8 should give a miles value of 5.
If it does not work, fix the problem.
-
Repeat the above to convert kilometers to miles.
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 hw3 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 © 2021 Glenn Hoffman. All rights reserved. May not be reproduced without permission.