Question

i need a python code

For an exact conversion between Fahrenheit temperature scale and Celsius temperature scale, the following formulas can be

The output of this program is as follows: Problem 07 Example 1: Enter a degree: -123.45 Enter a degree: -123,450 -190,21F Pro

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:
#flag to find if entered string is in right format
tempflag = False
#while loop till user enter temperature in right format
while(tempflag==False):
#asking user to input temperature
temp = input("Enter a degree: ")
#checking the format
if (temp[-1]=='c' or temp[-1]=='C'):
#checking if temp can be converted to float
try:
float(temp[:len(temp)-1])
tempflag=True
except:
tempflag=False
if(tempflag==True):
#if satisfies above condition, convert it to fahrenheit
celcius = float(temp[:len(temp)-1])
fahrenheit = ((9 * celcius) / 5) + 32
#converting float to upto only 2 decimal places
fahrenheit1 = round(fahrenheit,2)
print(fahrenheit1,'\bF')
  
#checking the format
if (temp[-1]=='f' or temp[-1]=='F'):
#checking if temp can be converted to float
try:
float(temp[:len(temp)-1])
tempflag=True
except:
tempflag=False
#converting to celcius
if(tempflag==True):
fahrenheit = float(temp[:len(temp)-1])
celcius = (5*(fahrenheit - 32))/9
#converting float to upto only 2 decimal places
celcius1=round(celcius,2)
print(celcius1,"\bC")

Code photo:
#flag to find if entered string is in right format tempflag = False #while loop till user enter temperature in right format wOutput:
Enter a degree: -123.45 Enter a degree: -123.45C - 190.21F
Enter a degree: 12 Enter a degree: 34.53 Enter a degree: 12ab Enter a degree: 345d Enter a degree: +100C 212.0F
Enter a degree: 980 208.4F
Enter a degree: 98f 36.67C
Enter a degree: 12315 Enter a degree: kl90 Enter a degree: - 12 Enter a degree: -42.34F -41.30

Add a comment
Know the answer?
Add Answer to:
i need a python code For an exact conversion between "Fahrenheit temperature scale" and "Celsius temperature...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • FOR PYTHON Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice...

    FOR PYTHON Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The program should use two custom functions, f_to_c and c_to_f, to perform the conversions. Both of these functions should be defined in a custom module named temps. Custom functionc_to_f should be a void function defined to take a Celsius temperature as a parameter. It should calculate and print the equivalent Fahrenheit temperature accurate to three decimal places. Custom function f_to_c should be a...

  • Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The...

    Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The program should use two custom functions, f_to_c and c_to_f, to perform the conversions. Both of these functions should be defined in a custom module named temps. Custom function c_to_f should be a void function defined to take a Celsius temperature as a parameter. It should calculate and print the equivalent Fahrenheit temperature accurate to three decimal places. Custom function f_to_c should be a value-returning...

  • Fahrenheit scale is a temperate scale and it uses the degree Fahrenheit (symbol °F) as the...

    Fahrenheit scale is a temperate scale and it uses the degree Fahrenheit (symbol °F) as the unit. Celsius scale is another temperature scale and its symbol is °C. Fahrenheit is used by United States whereas all other countries in the world use Celsius. The formulas of conversion between Fahrenheit and Celsius are as follows: From Fahrenheit: [°C] = ([°F] − 32) × 5⁄9 From Celsius: [°F] = [°C] × 9⁄5 + 32 Write a function named convertTemp( degree, ForC )...

  • Use Python to create a function that collects temperature in degree Celsius as input from a...

    Use Python to create a function that collects temperature in degree Celsius as input from a user and converts it to degree Fahrenheit. The same function should convert temperature from degree Fahrenheit to degree Celsius if the temperature provided was in degree Fahrenheit. You can use branching (for example, if-else) statements within the body of your function ( Hint: First collect the number, then also collect the unit of temperature so you can use that unit of temperature as a...

  • Temperature Converter Create a temperature conversion program that will convert the following to Fahrenheit: Celsius Kelvin...

    Temperature Converter Create a temperature conversion program that will convert the following to Fahrenheit: Celsius Kelvin Newton Your program should take a character which represents the temperature to convert from and a value to be converted to using the following specification: C - Celsius K - Kelvin N - Newton In addition your program should take in the following character to exit the program: X - eXit the program The numeric input for your program should be of type double....

  • Convert the given Celsius temperature to its equivalent temperature on the Fahrenheit scale. Where appropriate, round...

    Convert the given Celsius temperature to its equivalent temperature on the Fahrenheit scale. Where appropriate, round to the nearest tenth of a degree. 33) 59°C

  • 11) The formula C = -32) expresses the relationship between Fahrenheit temperature, F, and Celsius temperature,...

    11) The formula C = -32) expresses the relationship between Fahrenheit temperature, F, and Celsius temperature, C. Use the formula to convert 50°F to it equivalent temperature on the Celsius scale, rounded to the nearest degree A) 28°C B) -4°C C) 32°C D) 10°C I

  • Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The...

    Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The program should use two custom functions, f_to_c and c_to_f, to perform the conversions. Both of these functions should be defined in a custom module named temps. Custom function c_to_f should be a void function defined to take a Celsius temperature as a parameter. It should calculate and print the equivalent Fahrenheit temperature accurate to three decimal places. Custom function f_to_c should be a value-returning...

  • Create a program in Python that will allow the user to enter a temperature in Fahrenheit...

    Create a program in Python that will allow the user to enter a temperature in Fahrenheit which will then be converted to degrees Celsius. The program will keep asking the user for a Fahrenheit temperature until the user enters Q to quit. After each conversion the program needs to print out the degrees Celsius. The input prompts for this problem need to look like the following: Degrees Fahrenheit: Continue: For these input prompts watch the capitalization and spacing. There are...

  • Needs to be solved in MATLAB Problem 4 Produce a conversion table for Celsius and Fahrenheit...

    Needs to be solved in MATLAB Problem 4 Produce a conversion table for Celsius and Fahrenheit temperatures. The input to the function should be two numbers: Tlower and Tupper Which define the lower and upper range, in Fahrenheit, for the table The output of the function should be a two column matrix with the first column showing the temperature in Fahrenheit, from Tlower (32 °F) to Tupper (212 °F) with an increment of 5 °F, and the second column showing...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT