Practice problem (DS250723)

Write a Python program to convert temperatures to and from Celsius and Fahrenheit.

Formula : c/5 = f-32/9 where c = temperature in celsius and f = temperature in fahrenheit

Expected Output :

60°C is 140 in Fahrenheit

45°F is 7 in Celsius

2 Likes

Example conversions

celsius_temperature = int(input(“Enter celsius temperature: “))
fahrenheit_temperature = (celsius_temperature * 9 / 5) + 32
print(f”{celsius_temperature}°C is {fahrenheit_temperature:.2f} in Fahrenheit”)

fahrenheit_temperature = int(input(“Enter fahrenheit temperature: “))
celsius_temperature = (fahrenheit_temperature - 32) * 5 / 9
print(f”{fahrenheit_temperature}°F is {int(celsius_temperature)} in Celsius”)

1 Like

celsius_temp = int(input("enter celisius temp: "))

fahren_temp = (celsius_temp*9/5)+32

print(fahren_temp,“f”)

celsius_temperature = int(input("Enter Celsius Temperature : "))

fahrenheit_temperature = (celsius_temperature * 9 / 5) + 32

print(f"{celsius_temperature}°C is {fahrenheit_temperature:.2f} in Fahrenheit")

fahrenheit_temperature = int(input("Enter fahrenheit temperature: "))

celsius_temperature = (fahrenheit_temperature - 32) * 5 / 9

print(f"{fahrenheit_temperature}°F is {celsius_temperature:.2f} in Celsius")

print(“1. Convert Celsius_temperature to Fahrenheit”)

print(“2. Convert Fahrenheit_temperature to Celsius”)

program to convert temperatures to and from Celsius and Fahrenheit

cel_temp = int(input(‘Enter celsius temperature: ‘))
fahren_temp = (cel_temp * 9 / 5) + 32
print(cel_temp,chr(176),‘C is in’,fahren_temp,chr(176),‘F’)
print(’************************************************’)
fahren_temp = int(input('Enter fahrenheit temperature: '))
cel_temp = (fahren_temp - 32) * 5 / 9
print(fahren_temp,chr(176),‘F is in’,cel_temp,chr(176),‘C’)

Note: chr(176) to print the degree symbol in output

def Celsiu2Fahrenheits(c):
f = 9c//5+32
return f
def Fahrenheit2Celsius(f):
c = 5
(f-32)//9
return c

temp1 = int(input(“enter temperature in Celsius : “))
res1 = Celsiu2Fahrenheits(temp1)
print(f”{temp1}⁰C is {res1} in Fahrenheit”)
temp2 = int(input(“Enter temperature in Fahrenheit : “))
res2 = Fahrenheit2Celsius(temp2)
print(f”{temp2}⁰F is {res2} in Celsius”)

Ouput:

enter temperature in Celsius : 60

60⁰C is 140 in Fahrenheit

Enter temperature in Fahrenheit : 45

45⁰F is 7 in Celsius