2016-11-09 94 views
0

「類型錯誤:需要浮點數」 我正在爲Python 2.7中的切線,正弦和餘弦計算器。我在第10行得到了錯誤TypeError: a float is required。有人可以向我解釋這個或給我一個如何解決它的例子嗎?Python輻射計算器類型錯誤:需要浮點數

import math 
tan = math.tan 
cos = math.cos 
sin = math.sin 

while True: 
    selection=raw_input("Please Select:") 
    if selection =='1': 
     Tanswer=raw_input("Enter The Tangent:") 
     print tan(Tanswer) 
    elif selection == '2': 
     print "Work In Progress" 
    elif selection == '3': 
     print "Work In Progress" 
    elif selection == '4': 
     break 
    else: 
     print "Unknown Option Selected!" 

回答

0

原始輸入功能給你一個字符串值,所以你應該寫

Tanswer=float(raw_input("Enter The Tangent:")) 

把字符串轉換爲一個float

+0

非常感謝你:) – AdamG