Skip to main content
  1. Posts/

Convert Celsius Fahrenheit

·245 words·2 mins

Hello, Today i made a program that converts celsius to fahrenheit heres a breif step of what I did.

part 1 Making the program #

Step 1.) Made a function with a variable called c Step 2.) Made another variable to store the calculations Step 3.) Returned the value in fahrenheit Step 4.) Called the function Step 5.) Used a statement meaning if you run the program in the current file it will use the value that is typed in otherwise if you imported the function in another file and call it with a different value it will use the value in the file

Here is what the code should look like:

def convert_c_to_f(c):  
    farenheit = c * 1.8 + 32
    return(farenheit)


if __name__ == '__main__':
    print(convert_c_to_f(1))

Here is the sample output:

33.8

Part 2 Importing the program #

I basically imported the program into another program and added input and a function called try and except basically try means if the user types in a good value in my case a interger it will execute the message the except is the opposite instead it will print a error message if you type in a wrong value like a string in my case.

Here is what it should look like:

from conversion_library import convert_c_to_f

try:
    i = int(input("Enter the tempreture in Celsius: "))
    print(f"{i}°C is {convert_c_to_f(i)}°F")
except:
    print("You did not enter a number.")
Enter the tempreture in Celsius: 1
1°C is 33.8°F

here is the sample code: