Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Learning python, I'm trying to make a fahrenheit conversion using a defined function

celsius = input("Please enter degrees in celcius: ")
fahrenheit = 0

def f_conversion(celsius):
    ((celsius * 1.8) + 32 == fahrenheit)



print("Your temp in fahrenheit is: " + str(fahrenheit))

Any clues on to why this isnt working out?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

First, there is no need to initialize variables in python. So setting fahrenheit to zero right away is unnecessary.

Second, in the function itself, you are making an equality call. == checks for equality while = sets variable values. Moreover, you are doing so backwards, fahrenheit would be on the left and assigned with = the result of the conversion.

Your script might instead look something like this:

celsius = float(input("Please enter degrees in celcius: "))

def conversion(celsius):
    return ((celsius * 9/5) +32)

result = conversion(celsius)

print (f"Your temp in fahrenheit is {result}")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading