Question: a Python program that aims to calculate the total resistance of resistors connected in series or the total capacitance of capacitors connected in series. Unfortunately,
a Python program that aims to calculate the total resistance of resistors connected in series or the total capacitance of capacitors connected in series. Unfortunately, the program fails to compute the correct sum. Figure shows the Python code as written by the student:
aIdentify two errors in the program. Which lines are they in Are these syntax or semantic errors?
#binpython
# Program to calculate the sum of resistors or capacitor connected in series
printType of component to sum:"
print Input for resistors"
printInput C for capacitors"
Typeofcomponent inputEnter type of component:"
numberofcomponent floatinputInput total number of components to be added:"
componentnumber
TotalCapacitance
TotalResistance
if Typeofcomponent :
while componentnumber numberofcomponent:
floatinputInput capacitor value:"
if :
printOnly nonzero positive capacitor values are allowed"
else:
TotalCapacitance TotalCapacitance C
componentnumber componentnumber
TotalCapacitance TotalCapacitance
printThe total capacitance is : TotalCapacitance, "Farads"
else:
while componentnumber numberofcomponent:
floatinputInput resistor value:"
if :
printOnly nonzero positive resistor values are allowed"
else:
TotalResistance TotalResistance R
componentnumber componentnumber
printThe total resistance:", TotalResistance, "Ohm"
bCorrect the errors in part a and run the new program using the capacitor values of: F F F and F
Paste in a screenshot of the program and its output.
cModify the Python code, such that once it has performed a calculation and reported the result, it asks again for the type of components and performs a new calculation.
The program should now terminate when the input value to Enter type of component: is the word Exit
Paste in a screenshot of the program and its output.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
