嘿伙計們,我需要弄清楚括號在以下運算式的代碼中的位置,并且對括號實際進入的位置有點困惑。我一直在弄錯。
表達
x = float(input('Enter a value for x: '))
# Insert parentheses in the following line to fix the expression.
y = x - 1 ** 0.5 1 / 5
print('y = ' str(y))
uj5u.com熱心網友回復:
y = ( ( (x - 1 ) ** 0.5 ) 1 ) / 5
uj5u.com熱心網友回復:
由于python中的求值順序,您實際上需要三組它們。
像這樣 :
y = (((x - 1) ** 0.5) 1 )/ 5
uj5u.com熱心網友回復:
平方根和分子周圍的括號應該清楚。
y = ((x-1)**0.5 1) / 5
此外,您可以匯入“數學”。這使您可以按如下方式使用 sqrt():
y = (math.sqrt(x-1) 1) / 5
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/396990.html
下一篇:如何計算兩個數字的最小值?
