我的目標是創建一個將度數轉換爲弧度的程序。其計算公式爲(度* 3.14)/ 180但是Python不斷給我這個錯誤:在python中浮動字符串時遇到問題
Traceback (most recent call last):
File "2.py", line 6, in <module>
main()
File "2.py", line 4, in main
degrees = (degrees * 3.14)/180
TypeError: can't multiply sequence by non-int of type 'float'
從這個代碼:
def main():
degrees = raw_input("Enter your degrees: ")
float(degrees)
degrees = (degrees * 3.14)/180
main()
編輯:謝謝大家的幫助!
我只想補充一點,字符串是不可變的蟒蛇因而對他們的所有操作創建一個新的對象,從來沒有修改原始。 – Zenon 2012-04-01 01:29:56
謝謝!是的,我知道,但是我的老師希望我爲自己做一個功能。 – netbyte 2012-04-01 01:33:50