I just started to learn Python. I tried to create a new function, but the terminal keeps returning the same kind of error.
TypeError: temperature() missing 1 required positional argument: 'float'
Below is my code:
def temperature(celsius, float) -> float:
fahrenheit = (celsius*(9/5)+32)
return fahrenheit
celsius = float(input("Input the temperature in Celsius that you want to have in Fahrenheit: "))
temperature(celsius)
print("The temperature in Fahrenheit is: ", temperature, "°F")
Can you help me figure out what's going on?
Shouldn't this be what you are looking for. Remove the float from the parameter list in the temperature function? With celsius and float as parameters your temperature function was expecting you to pass it two parameter. You only needed to pass it one celsius.
Also, you need to store the return of the tempurature method before printing it. Notice how I modified the last to lines with the
tempvariable. You store the output of the temperature function call in temp. Then you print temp on the last line.