Write a Python program that prompts the user to enter a numeric temperature value that may be a float. A second prompt should then ask the user to indicate whether the user wants the entered temperature value converted to degrees Celsius or degrees Fahrenheit by entering either an 'F' or a 'C' for a second prompt. For example, if the user enters 212 at the first prompt and the character C for the second prompt you are to convert 212 degrees F to the Celsius equivalent (which would be 100.0). Converted temperatures should be rounded to 1 decimal place. If the user enters 26 at the first prompt and the character F at the second one, then your programs should convert 26 degrees C to the Fahrenheit equivalent (which is 78.8 deg F) Your conversion formulas are:
Operations
In mathematics and computer science, an operation is an event that is carried out to satisfy a given task. Basic operations of a computer system are input, processing, output, storage, and control.
Basic Operators
An operator is a symbol that indicates an operation to be performed. We are familiar with operators in mathematics; operators used in computer programming are—in many ways—similar to mathematical operators.
Division Operator
We all learnt about division—and the division operator—in school. You probably know of both these symbols as representing division:
Modulus Operator
Modulus can be represented either as (mod or modulo) in computing operation. Modulus comes under arithmetic operations. Any number or variable which produces absolute value is modulus functionality. Magnitude of any function is totally changed by modulo operator as it changes even negative value to positive.
Operators
In the realm of programming, operators refer to the symbols that perform some function. They are tasked with instructing the compiler on the type of action that needs to be performed on the values passed as operands. Operators can be used in mathematical formulas and equations. In programming languages like Python, C, and Java, a variety of operators are defined.
Write a Python program that prompts the user to enter a numeric temperature value that may be a float. A second prompt should then ask the user to indicate whether the user wants the entered temperature value converted to degrees Celsius or degrees Fahrenheit by entering either an 'F' or a 'C' for a second prompt.
For example, if the user enters 212 at the first prompt and the character C for the second prompt you are to convert 212 degrees F to the Celsius equivalent (which would be 100.0). Converted temperatures should be rounded to 1 decimal place.
If the user enters 26 at the first prompt and the character F at the second one, then your programs should convert 26 degrees C to the Fahrenheit equivalent (which is 78.8 deg F)
Your conversion formulas are:
degF = 1.8 * degC + 32 //convert Celsius to Fahrenheit
degC = (degF - 32) / 1.8 //convert Fahrenheit to Celsius
- Have your converted values be floats rounded to 1 decimal place.
- The F or C entry should be case-insensitive. The user should be able to enter F or f for a Fahrenheit conversion, or a C or c for a Celsius conversion. But if the user doesn't enter an F, f, C or c, then display an error message and exit the program rather than performing the calculation
- Use the decision structure of your choosing to determine whether to convert the input value to degF or degC or to exit.
- Your output should contain both the original temperature entered and the proper output temperature, labeled as to which is which. Something like this: 212 degrees F = 100.0 degrees C
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images
The code works, execpt:
Have your converted values be floats rounded to 1 decimal place.
How do you make it round to 1 decimal place?