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 1 shows the Python code as written by the student:
a.Identify two errors in the program. Which lines are they in? Are these syntax or semantic errors?
#!/bin/python 3
# Program to calculate the sum of resistors or capacitor connected in series
print("Type of component to sum:")
print ("Input 'R' for resistors")
print("Input 'C' for capacitors")
Type_of_component = input("Enter type of component:")
number_of_component = float(input("Input total number of components to be added:"))
component_number =1
Total_Capacitance =
Total_Resistance =0
if Type_of_component =='C' :
while component_number = number_of_component:
c= float(input("Input capacitor value:"))
if C0 :
print("Only non-zero positive capacitor values are allowed")
else:
Total_Capacitance = Total_Capacitance +1/C
component_number = component_number +1
Total_Capacitance =1/Total_Capacitance
print("The total capacitance is :", Total_Capacitance, "Farads")
else:
while component_number = number_of_component:
R= float(input("Input resistor value:"))
if R :
print("Only non-zero positive resistor values are allowed")
else:
Total_Resistance = Total_Resistance + R
component_number = component_number +1
print("The total resistance:", Total_Resistance, "Ohm")
b.Correct the errors in part (a) and run the new program using the capacitor values of: 1 F,0.5 F,0.05 F and 0.1 F.
Paste in a screenshot of the program and its output.
c.Modify 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.
 a Python program that aims to calculate the total resistance of

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!