Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 1.A 1. Fix the program to allow for fractional temperatures (such as 98.6 or 101.4) 2. Make the program stop (exit) if an invalid

Problem 1.A

 

1.Fix the program to allow for fractional temperatures (such as 98.6 or 101.4)

2.Make the program stop (exit) if an invalid value (such as a letter) is entered

3.Include error message(s)

1.Test with the following entries. The submission will be evaluated using these values.

If you enter:

You should get this for

degrees Celsius

You should get this for

degrees Kelvin

-32.6

-35.888888888888886

237.2611

32

0

273.15

98.6

37

310.15

212.0

100

373.15

John Doe

Error message

Error message

32F

Error message

Error message

 
Hint! One try/exit combination and one data type change is sufficient for this assignment. 
Hint: Use the National Institute of Standards and Technology URL for formula conversions: https://www.nist.gov/pml/weights-and-measures/si-units-temperature 
 

Use this temperature conversion program:

# Prompt user for temperature  
tempF = int(input("Enter the temperature in degrees F: ")) 
# Formula for converting Fahrenheit to Celsius tempC = (tempF - 32)*(5/9) # Formula for converting Fahrenheit to Kelvin tempK = (5/9*(tempF - 32) + 273) # Now display the results print(str(tempF) + " degrees Fahrenheit equals " + str(tempC) + " degrees Celsius or " + str(tempK) + " degrees Kelvin") 

Problem 1.B

This is also a temperature conversion program, but it allows entry of both the number and the type (such as C or F) and can convert between the two.

2.Fix the program to allow for fractional temperatures (such as 98.6 or 101.4)

3.Edit the program so that:

a. it stops (exits) if an invalid temperature is entered, and

b.displays a new error message #1 that explains what happened

4.Test with the following entries. The submission will be evaluated using these values.

If you enter:

You should get this:

F or C alone

Error message

-32.6F

-35.888888888888886

32F

0.0

98.6F

37.0

100C

212.0

212.0F

100.0

John

Error message

 
Hint! One try/exit combination, one new error message, and one data type change is sufficient for this problem.  
 

Use this temperature conversion program:

# Basic program for illustrating exception handling # KAS 4/13/17 BMI 5310 # from http://www.w3resource.com/python-exercises/python-

# conditional-exercise-2.php # ------------------------------------------------------- # Use these values to test your final code (at a minimum) # # Input Expected result # F or C alone Error message # -32.6F -35.888888888888886 # 32F 0.0 # 98.6F 37.0 # 100C 212.0 # 212.0F 100.0 # John Error message # ------------------------------------------------------- temp = input("Please enter the temperature you would like to convert (e.g., 98.6F, 100C etc.) : ") # Now break the input into two - # the temperature in degrees, which is everything entered except the last character # and the temperature type that was input, such as Fahrenheit or Celsius, which is only the last character of the input degree = int(temp[:-1]) i_temptype = temp[-1] # Now if the temperature type was C if i_temptype.upper() == "C": # If so, convert the degrees value and store the value in a new variable called result result = (9 * degree) / 5 + 32 # and set the output temperature type as Fahrenheit o_temptype = "Fahrenheit" # Otherwise, check if the temperature type was F elif i_temptype.upper() == "F": # If so, convert the degrees value and store the value in a new variable called result result = (degree - 32) * 5 / 9 # and set the output temperature type as Celsius o_temptype = "Celsius" # Otherwise, it must not be either so ask for a correct temperature type else: print("Error #2: Please enter a temperature with both number and type, either C or F.") quit() # Everything is OK so output the result print("The temperature in", o_temptype, "is", result, "degrees.")

 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Bioinformatics Databases And Systems

Authors: Stanley I. Letovsky

1st Edition

1475784058, 978-1475784053

More Books

Students also viewed these Databases questions