本文實(shí)例講述了python簡(jiǎn)單的函數(shù)定義和用法。分享給大家供大家參考。具體分析如下:
這里定義了一個(gè)溫度轉(zhuǎn)換的函數(shù)及其用法。
def convertTemp(temp, scale): if scale == "c": return (temp - 32.0) * (5.0/9.0) elif scale == "f": return temp * 9.0/5.0 + 32temp = int(input("Enter a temperature: "))scale = input("Enter the scale to convert to: ")converted = convertTemp(temp, scale)print("The converted temp is: " + str(converted))
希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選