a = int(float(input("Add : ")))
b = int(float(input("Add : ")))
c = print(" = " , a**2 b**2)
print(c/2)
我打算將變數和數字分開,但它發生了這樣的情況,我該如何解決?| TypeError:不支持的運算元型別/:'NoneType'和'int'
uj5u.com熱心網友回復:
print回傳None,您分配給c。None不能除以 int,因此您的錯誤。
如果你想存盤a**2 b**2in的結果c,那么直接這樣做:
a = int(input("Add: "))
b = int(input("Add: "))
c = a**2 b**2
print(f"{a=}, {b=}, {c=}")
print(c / 2)
樣本輸出:
Add: 3
Add: 5
a=3, b=5, c=34
17.0
uj5u.com熱心網友回復:
print是一個函式,它回傳None并將其 args 列印到stdout. 因此 c 具有價值None。并None / 2給出TypeError
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/495356.html
下一篇:基于陣列中最常見數字的權重選擇
