为什么我会收到 SyntaxError?

Why am I receiving a SyntaxError?

我正在处理的问题是要求我修改现有代码如下:

The following program uses a list to store a user-entered set of resistance values and computes I. Modify the program to compute the voltage drop across each resistor, store each in another list voltage_drop, and finally print the results in the specified format.

这是未经我修改的代码:

resistors = []
voltage_drop = []

print( '%d resistors are in series.' % num_resistors)
print('This program calculates the'),
print('voltage drop across each resistor.')

input_voltage = float(input('Input voltage applied to circuit: '))
print (input_voltage)

print('Input ohms of {} resistors'.format(num_resistors))
for i in range(num_resistors):
    res = float(input('{})'.format(i + 1)))
    print(res)
    resistors.append(res)

#  Calculate current
current = input_voltage / sum(resistors)

# Calculate voltage drop over each resistor
# ...

# Print the voltage drop per resistor
# ...


这是我修改后的代码:

resistors = []
voltage_drop = []

print( '%d resistors are in series.' % num_resistors)
print('This program calculates the'),
print('voltage drop across each resistor.')

input_voltage = float(input('Input voltage applied to circuit: '))
print (input_voltage)

print('Input ohms of {} resistors'.format(num_resistors))
for i in range(num_resistors):
    res = float(input('{})'.format(i + 1)))
    print(res)
    resistors.append(res)

#  Calculate current
current = input_voltage / sum(resistors)

# Calculate voltage drop over each resistor
for res in resistors:
    vol_drop = current * res
    voltage_drop.append(vol_drop)

# Print the voltage drop per resistor

print('Voltage drop per resistor is')
for voldrop in voltage_drop:
    print('{}) {:.2f} V'.format(voltage_drop.index(voldrop), voldrop)

如果我注释掉最后三行或将其更改为仅打印电压降,它就可以正常工作。它应该打印成

  1. 第一个数字
  2. 第二个数字 等等。

这是我收到的错误:

文件“main.py”,第 31 行

语法错误:解析时出现意外的 EOF

打印语句缺少结束符“)”:

 print('{}) {:.2f} V'.format(voltage_drop.index(voldrop), voldrop)