Temperature Converter Program

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

def celsius_to_fahrenheit(celsius):

• This line defines a function named celsius_to_fahrenheit


that takes one parameter celsius, representing the temperature in Celsius.
TEMPERATURE CONVERTER

fahrenheit = (celsius * 9/5) + 32 return fahrenheit

• This line returns the calculated temperature in Fahrenheit to the


This line calculates the equivalent temperature in caller of the function.
Fahrenheit using the formula (Celsius × 9/5) + 32, where celsius is
the input temperature in Celsius. It stores the result in a variable named fahrenheit
celsius = float(input("Enter temperature in
Celsius: "))
fahrenheit = celsius_to_fahrenheit(celsius)

• This line calls the celsius_to_fahrenheit function


• This line prompts the user to enter a temperature in Celsius using
with the user-provided temperature in Celsius as an argument.
the input() function. The input value is read as a string and
It assigns the returned temperature in Fahrenheit to a variable named fahrenheit
converted to a floating-point number (float()) to handle decimal values.

print("Temperature in Fahrenheit:",
PROGRAM FOR COVERTING TEMPERATURE
fahrenheit)
• def celsius_to_fahrenheit(celsius):
• fahrenheit = (celsius * 9/5) + 32
• This line prints the calculated temperature in Fahrenheit to the console. • return fahrenheit

The temperature value is concatenated with the string "Temperature in Fahrenheit:"


• # Input temperature in Celsius
and displayed using the print() function. • celsius = float(input("Enter temperature in Celsius: "))

• # Convert Celsius to Fahrenheit


• fahrenheit = celsius_to_fahrenheit(celsius)

• # Display the result


• print("Temperature in Fahrenheit:", fahrenheit)
THANK YOU …

- AMEER HASSAN
2AB22BA003

You might also like