top of page
learn_data_science.jpg

Data Scientist Program

 

Free Online Data Science Training for Complete Beginners.
 


No prior coding knowledge required!

Python App to Convert temperature in Fahrenheit to Celsius.

Writer: Ahmed SheblAhmed Shebl

I made a function that takes one argument (fah) which is the degree in Fahrenheit



def fah_to_cel(fah):
    # (32°F − 32) × 5/9 = 0°C
    cel = (fah -32) * 5 / 9
    
    return cel


I used the equation of converting Fahrenheit to Celsius in the above function.


Then, I use input() funtion to get the temperature degree in Fahrenheit from user and and flaot() function to convert it from string to float, so I can use it in calculation in the function.


I put my code in try...except to check if the user input can be converted to float or not, and not crashed by wrong input data, if it can converted the program continue executing, if not it will print a message to the user.


Then I call my function with the user input to get the temperature in Celsius.

Finally I return the result which is the temperature degree in Celsius.




print("Enter temperature in Fahrenheit")
try:
    fah = float(input())
    
    cel = fah_to_cel(fah)

    print("The temperature " + str(fah) + " in Fahrenheit = " + str(cel) + " in Celsius.")
    
except ValueError:
    print("The temperature degree you entered not a number")


The complete code is here:




def fah_to_cel(fah):
    # (32°F − 32) × 5/9 = 0°C
    cel = (fah -32) * 5 / 9
    
    return cel

print("Enter temperature in Fahrenheit")
try:
    fah = float(input())
    
    cel = fah_to_cel(fah)

    print("The temperature " + str(fah) + " in Fahrenheit = " + str(cel) + " in Celsius.")
    
except ValueError:
    print("The temperature degree you entered not a number")





 
 

Comments


COURSES, PROGRAMS & CERTIFICATIONS

 

Advanced Business Analytics Specialization

Applied Data Science with Python (University of Michigan)

Data Analyst Professional Certificate (IBM)

Data Science Professional Certificate (IBM)

Data Science Specialization (John Hopkins University)

Data Science with Python Certification Training 

Data Scientist Career Path

Data Scientist Nano Degree Program

Data Scientist Program

Deep Learning Specialization

Machine Learning Course (Andrew Ng @ Stanford)

Machine Learning, Data Science and Deep Learning

Machine Learning Specialization (University of Washington)

Master Python for Data Science

Mathematics for Machine Learning (Imperial College London)

Programming with Python

Python for Everybody Specialization (University of Michigan)

Python Machine Learning Certification Training

Reinforcement Learning Specialization (University of Alberta)

Join our mailing list

Data Insight participates in affiliate programs and may sometimes get a commission through purchases made through our links without any additional cost to our visitors.

bottom of page