Did you try changing the order of return and print()? (Unless you just want to return the temperature conversion(?)).
I don’t think the question asks for a keyword argument, just positional so you can call the function with any argument (temperature).
I know it didn’t ask for keyword; I was just trying some stuff out. BUT I don’t know why it would work for you but not for me. At least it makes sense the way I did it?
Did you expand the “Summary” to view the edited code that I provided?
Also, I used an external IDE and not the learning environment to test the code. Sometimes in the LE, if you don’t have exactly what they’ve asked for, your code won’t work (pass the tests behind the scenes).
If you want to make changes to the code/beyond what’s asked, I recommend using an IDE or code editor (or, if you’re on a mac, Terminal).
Oh my goodness my jaw is on the floor. I didn’t catch the thing about putting the return statement after but that fixed it. My question is why was it necessary to move it to after the print statement? If you can offer an explanation without too much trouble I’d appreciate it. Thank you for your time!
the question doesn’t ask one to print anything. Just return a value to the caller.
The return statement immediately terminates the function, and returns the value back. So anything placed after that inside the function isn’t recognized (like your original print()) . So, then you move it before the return. In your code, the item returned when the function is called is temp_c.
def f_to_c(f_temp): #parameter, f_temp
temp_c = (f_temp - 32) * 5/9
print(str(f_temp) + " degrees Farenheit converts to " + str(temp_c) + " degrees Celsius.")
return temp_c #this value is returned when you call the function.
f_to_c(400) #calling the function and passing an argument "through" it.
It’s a good habit to get into–to move pieces of code around to see how it/they act–if stuff throws an error or not to really try to understand what it’s doing.
Poking my head in here with a shout out to the folks who were responsible for implementing the most recent string formatting method: f-string. That one improvement added to workflow more than any recent revisions to the language. It certainly eliminated a slough of typos!
print (f"{f_temp} degrees Farenheit converts to {temp_c} degrees Celsius.")
Now that one is aware of this string formatting method it becomes pointless to think of string concatenation, ever again.