반응형
>>> def main():
fahrenheit = eval(input("Enter the value for F: "))
celsius = fahrenheit - 32 * 5/9
print("The value from Fahrenheit to Celsius is " + celsius)
>>> main()
Enter the value for F: 32
Traceback (most recent call last):
File "<pyshell#73>", line 1, in <module>
main()
File "<pyshell#72>", line 4, in main
print("The value from Fahrenheit to Celsius is " + celsius)
TypeError: Can't convert 'float' object to str implicitly"
해결 방법
floats
는 암시 적으로 문자열로 변환 될 수 없습니다. 명시 적으로해야합니다.
print("The value from Fahrenheit to Celsius is " + str(celsius))
그러나 형식
을 사용하는 것이 좋습니다.
print("The value from Fahrenheit to Celsius is {0}".format(celsius))
참조 페이지 https://stackoverflow.com/questions/22397261
반응형
'파이썬' 카테고리의 다른 글
파이썬 Python의 'in'연산자를 재정의 하시겠습니까? (0) | 2020.12.20 |
---|---|
파이썬 Inserting a value into all possible locations in a list (0) | 2020.12.20 |
파이썬 Locate first and last non NaN values in a Pandas DataFrame (0) | 2020.12.20 |
파이썬 한 열의 python pandas pivot_table 카운트 빈도 (0) | 2020.12.20 |
파이썬 Python의 목록에있는 각 튜플의 첫 번째 요소를 가져옵니다. (0) | 2020.12.20 |
댓글