简体   繁体   中英

"converting temperature from f into c" not working in def

Problem: Convert

f=c9/5 +32

using def function.

I have tried this:

def calculator ():
    c=input("write celcius")
    f=int(c)*9/5+32
    return f

print(calculator)

PS F:> python .\\q.py function calculator at 0x030F0810

Since calculator is a function, not a variable you should use print(calculator()) . Also you should fix the indentation of your return statement. A return statement should be inside the function block. This should work

def calculator ():
    c=input("write celcius")
    f=int(c)*9/5+32
    return f

print(calculator())

There is an indentation error in your code. You should add the return statement inside the function.

And also add parenthesis () to the function where ever you are calling the function.

The solution :

def calculator ():
    c=input("write celcius")
    f=int(c)*9/5+32
    return f

print(calculator())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM