Starting from:

$15

CS 3030 Scripting Languages - Lab 4: temp

Introduction Lab 4 is your first Python script and it is a simple one. It is interactive, meaning your script will prompt
the user to enter a temperature in degrees Fahrenheit or Celsius and calculate the other, in a continuous
loop until the user exits the program.
Requirements
Your script shall be named ~/cs3030/lab4/temp and be marked executable. Here is how you
execute your script:
./temp
Your script shall interact with the user. The first thing it should print is exactly this:
Welcome to the CS 3030 Temperature Conversion Program
This welcome message should be printed only once. Your program should then loop until the user enters “3” to exit the program. Your script should prompt the
user with this main menu: Main Menu
1:Fahrenheit to Celsius
2:Celsius to Fahrenheit
3:Exit program
Please enter 1, 2 or 3:
The user then enters 1, 2 or 3 (and hits ENTER)
If the user enter “3”, the program exits.
If the user enters a “1”, the user is prompted for degrees Fahrenheit with this prompt:
Please enter degrees Fahrenheit:
The user enters a number, which should not contain commas but can contain a decimal point or a minus
sign. Assume the user enters “56.2”. The program should respond with:
1 of 4
CS 3030 Scripting Languages
Lab 4: temp
56.2 degrees Fahrenheit equals 13.4 degrees Celsius
The program then reprints the main menu and prompts the user, in an endless loop.
If the user enters a “2”, the user should be prompted for degrees Celsius with this prompt:
Please enter degrees Celsius:
The user enters a number as before, which should not contain commas but can contain a decimal point or a
minus sign. Assume the user enters “91.8”. The program should respond with:
91.8 degrees Celsius equals 197.2 degrees Fahrenheit
If at any time the user enters anything non-numeric (including hitting just ENTER), your script should trap
the error and at a minimum, print a message that includes:
Invalid entry
You should then reprint the main menu and start over at the beginning. Do not re-prompt for the degrees,
start over at the top.
Your script should include these two functions to calculate its results:
def fahrenheitToCelsius(fahrenheit) - converts degrees fahrenheit to degrees celsius
using this formula: C = (F - 32.0) * (5.0/9.0)
def celsiusToFahrenheit(celsius) - converts degrees celsius to degrees fahrenheit using
this formula: F = (9.0/5.0) * C + 32.0
2 of 4
CS 3030 Scripting Languages
Lab 4: temp
Hints
• Use try/except to trap errors when prompting the user or converting the incoming string to a number
• Always restart from the main menu when the user enters anything invalid
• Always restart from the main menu after calculating degrees
• Your script should expect the user to hit ENTER after each entry
• Exit immediately when the user enters 3 from the main menu
• Use whitespace and indenting to make your script readable
• Add comments to your script to document your logic
Run cucumber to determine your grade
• Because temp is interactive, the first thing you should implement and test is typing 3 to exit. The
cucumber scripts rely on this feature and it must work.
• The cucumber files for this lab implements a random number generator. To ensure your program
always produces the correct output, run cucumber multiple times.
• When using cucumber, the tar command only needs to be run once (unless I update the cuke.tar
file and notify the class)
tar xvf /var/classes/cs3030/lab4/cuke.tar
./cucumber -s
Files
For this lab you will have created folder lab4 and the following executable files:
temp
3 of 4
CS 3030 Scripting Languages
Lab 4: temp
Grading
Here is how you earn points for this assignment: FEATURES POINTS Must-Have Features
Script is named correctly and found in its proper place on icarus 5
Script is executable 5
Required Features
Script prints “Welcome to the CS 3030 Temperature Conversion Program” 5
Script prints the Main Menu 5
Script correctly converts degrees Fahrenheit to degrees Celsius with 1 decimal
place with option 1
10
Script correctly converts degrees Celsius to degrees Fahrenheit with 1 decimal
place with option 2
10
Script exits with option 3 10
Script uses function fahrenheitToCelsius() 10
Script uses function celsiusToFahrenheit() 10
Script recovers from non-numeric entry at main menu 10
Script recovers from non-numeric entry when prompting for degrees Fahrenheit 10
Script recovers from non-numeric entry when prompting for degrees Celsius 10
Grand Total 100
4 of 4

More products