努力找出插入括号的位置
Struggling to figure out where to insert perentheses
大家好,我需要弄清楚以下表达式的括号在这段代码中的位置,但对括号的实际位置有点困惑。我总是弄错。
Expression
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))
平方根和分子两边的括号应该清楚。
y = ((x-1)**0.5 + 1) / 5
此外,您可以导入 'math'。这使您可以按如下方式使用 sqrt():
y = (math.sqrt(x-1) + 1) / 5
y = ( ( (x - 1 ) ** 0.5 ) + 1 ) / 5
由于python中的求值顺序,实际上需要三组。
像这样:
y = (((x - 1) ** 0.5) + 1 )/ 5
大家好,我需要弄清楚以下表达式的括号在这段代码中的位置,但对括号的实际位置有点困惑。我总是弄错。
Expression
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))
平方根和分子两边的括号应该清楚。
y = ((x-1)**0.5 + 1) / 5
此外,您可以导入 'math'。这使您可以按如下方式使用 sqrt():
y = (math.sqrt(x-1) + 1) / 5
y = ( ( (x - 1 ) ** 0.5 ) + 1 ) / 5
由于python中的求值顺序,实际上需要三组。
像这样:
y = (((x - 1) ** 0.5) + 1 )/ 5