我是編碼方面的初學者。每當我嘗試進行計算時,Python 都會給我同樣的錯誤。我使用python 3.9。我輸入輸入時沒有打錯字(這個是 5.2)。請你幫助我好嗎?
"""
length of rectangle = a
width of rectangle = b
calculate the area and perimeter of the rectangle
"""
a = 6
b = float(input("width: "))
area = a*b
perimeter = (2*a) (2*b)
print("area: " str(area) " perimeter: " str(perimeter))
Traceback (most recent call last):
File "c:\Users\HP\OneDrive - Karabuk University\Belgeler\Downloads\first.py", line 8, in <module>
b = float(input("width: "))
ValueError: could not convert string to float: '5.2&
uj5u.com熱心網友回復:
代碼沒有問題,不是代碼,你的輸入鍵是否附加了一些隱藏字符
┌──[[email protected]]-[/]
└─$vim demo.py
┌──[[email protected]]-[/]
└─$python3 demo.py
width: 5.2
area: 31.200000000000003 perimeter: 22.4
┌──[[email protected]]-[/]
└─$cat demo.py
"""
length of rectangle = a
width of rectangle = b
calculate the area and perimeter of the rectangle
"""
a = 6
b = float(input("width: "))
area = a*b
perimeter = (2*a) (2*b)
print("area: " str(area) " perimeter: " str(perimeter))
┌──[[email protected]]-[/]
└─$
uj5u.com熱心網友回復:
這段代碼應該可以作業。我想問題是你的輸入:'5.2&'。你在這里打錯字了。Revove '&' 它會起作用。
uj5u.com熱心網友回復:
"""
length of rectangle = a
width of rectangle = b
calculate the area and perimeter of the rectangle
"""
a = 6
b = float(input("width: "))
area = a*b
perimeter = (2*a) (2*b)
print("area: " , area , " perimeter: " , perimeter)
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/526201.html
標籤:Python细绳值错误
上一篇:替換用于分類的數字標簽的字串
