def functions and floats - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: def functions and floats (/thread-10593.html) |
def functions and floats - alwillia - May-26-2018 def celcius(c): c = 0 return f=(1.8 * c) + 32 print celcius()Directions follow. I'm was just trying to get the first part before going on and I'm running into issues. Write a function that takes one parameter - a float which represents a temperature in Celcius - and returns a float which represents that temperature in Fahrenheit. Then, write a function that does the opposite conversion. Here are the formulas for temperature conversion: F=(1.8 x c) +32 C=(f-32) /1.8 Finally, write some code below your functions that uses them to convert 0 degrees Celcius and 100 degrees Celcius to Fahrenheit, and to convert 40 degrees Fahrenheit and 80 degrees Fahrenheit to Celcius. Make sure to print your results for the above to the console. RE: def functions and floats - buran - May-26-2018 there are number of errors in your code. Please, always post full traceback you get, in error tags... And we can work together to fix them all RE: def functions and floats - killerrex - May-26-2018 I comment inside your code: def celsius(c): # With the next line you are ignoring completely the input value and replacing it by 0 c = 0 # The next line is not valid python code, either define a variable f and return it # f = (1.8 * c) + 32 # return f # Or return the result of an operation and do not create the variable f # return (1.8 * c) + 32 return f=(1.8 * c) + 32 # You are learning python, using the print like this is python2 only. # As you are learning, I recommend to use python3 and then the print command needs (): # print(celsius()) print celsius() RE: def functions and floats - buran - May-26-2018 Just to add to what killerrex already said - you need to supply some number as argument c when calling function, e.g. print celsius(10.0) , i.e. you want to convert 10.0 degrees cecsiusalso, more appropriate name of the function is fahrenheit (or something like celsius2farenheit ) because you convert Celsius to farenheit, not the other way aroundalso instead of one char argument c, better use something descriptive like celcius
|