Why am I receiving a SyntaxError?

Question:

The problem I am working on is asking me to modify existing code as follows:

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.

Here is the code without my modifications:

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
# ...


Here is the code with my modifications:

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)

If I comment out the last three lines or change it to only print the drop in voltage, it works just fine. It’s supposed to print like

  1. first number
  2. second number
    and so on.

Here is the error I am receiving:

File "main.py", line 31

SyntaxError: unexpected EOF while parsing

Asked By: mo-mouse

||

Answers:

The print statement is missing a closing ‘)’:

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

indicated by the "SyntaxError: unexpected EOF while parsing"

Answered By: Allan Wind
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.