Python學習之溫度轉換實例分析篇

#TempConvert.py
Tempstr=input('請輸入要轉換的溫度值:')
if Tempstr[-1] in ['C','c']:
    F=1.8*eval(Tempstr[0:-1])+32
    print("轉換後的溫度值爲{:.2f}F".format(F))
elif Tempstr[-1] in ['F','f']:
    C=(eval(Tempstr[0:-1])-32)/1.8
    print("轉換後的溫度值爲{:.2f}C".format(C))
else:
    print('輸入格式有誤!')

1)python單行註釋用#,多行註釋用三對單引號'''........''';python

2)python的eval()函數能夠把字符串轉換爲數字;函數

3)python用format()函數能夠實現數據的格式化spa

4)python列表的索引正向從0開始,反向從-1開始;code

5)python能夠經過切片獲取列表的一段數據orm

 

另求助爲何這個程序在Pycharm中執行一次後不能自動結束?blog

相關文章
相關標籤/搜索