0% found this document useful (0 votes)
26 views3 pages

Temperature Converter Program

The document describes a Python program that defines a function to convert Celsius to Fahrenheit and uses it to prompt a user for temperature input in Celsius and output the equivalent in Fahrenheit.

Uploaded by

Ameer Hassan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views3 pages

Temperature Converter Program

The document describes a Python program that defines a function to convert Celsius to Fahrenheit and uses it to prompt a user for temperature input in Celsius and output the equivalent in Fahrenheit.

Uploaded by

Ameer Hassan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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