簡體   English   中英

“將溫度從 f 轉換為 c”在 def 中不起作用

[英]"converting temperature from f into c" not working in def

問題:轉換

f=c9/5 +32

使用 def 函數。

我試過這個:

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

print(calculator)

PS F:> python .\\q.py 函數計算器在 0x030F0810

由於計算器是一個函數,而不是一個變量,你應該使用print(calculator()) 此外,您應該修復 return 語句的縮進。 return 語句應該在功能塊內。 這應該工作

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

print(calculator())

您的代碼中存在縮進錯誤。 您應該在函數內添加 return 語句。

並且還在調用函數的函數中添加括號()

解決方案 :

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

print(calculator())

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM