Professional Documents
Culture Documents
Activity 3
Activity 3
Activity 3
LOOPS
SUBMITTED BY:
Abrigo, Renz Christian, B.
COE - 1203
SUBMITTED TO:
Sir Mark Rondol P. Abdon
● Calculate total resistance: Choose this option to calculate the total resistance of the circuit.
● The program will validate the input to ensure it consists of valid characters ('0' to '9' and '.').
● If the resistance value is valid and greater than zero, it will be added to the list of resistors, and a confirmation
message will be displayed.
● If the resistance value is not valid or less than or equal to zero, an appropriate error message will be
displayed.
2. Calculating Total Resistance:
● If no resistors have been added yet, the program will display a message indicating that no resistors have been
added.
● If resistors are present:
● The user must be prompted to enter the connection type (series or parallel).
● The program will sum up all the resistance values to calculate the total resistance.
The total resistance value will be displayed with two decimal places.
● For Parallel Connection:
● The program will calculate the total resistance using the formula:
Total Resistance = 1 / (1/R1 + 1/R2 + 1/R3 + ...) (Reciprocal of the sum of reciprocals of
all resistances)
● It iterates over each resistance value, calculates its reciprocal, and sums them up.
● Finally, it takes the reciprocal of the sum to obtain the total resistance of the parallel
circuit. The total resistance value will be displayed with two decimal places.
3. Exiting the Program:
● Choose this option to exit the program gracefully.
Note:
● Ensure to input valid resistance values (greater than zero) when adding resistors.
● When calculating the total resistance, choose either "series" or "parallel" connection type.
Please provide a screenshot of your program. Remember, it's essential to maintain originality when completing this
task.
def main():
while True: #Your program must present the options repeatedly
print("Resistor Manager and Total Resistance Calculator")
print("1. Add a Resistor")
print("2. Calculate Total Resistance")
print("3. Exit")
choice = int(input("Enter option: "))
if choice == 1: #Choose this option to calculate the total resistance of the circuit.
print("\n")
add_resistor()
elif choice == 2: #Choose this option to add a resistor to the circuit.
print("\n")
calc_total()
elif choice == 3: #Choose this option to exit the program.
print("\n")
print("Exiting program.") #Exit the program
break
Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Alangilan Campus
Golden Country Homes, Alangilan Batangas City, Batangas, Philippines 4200
Tel Nos.: (+63 43) 425-0139 local 2121 / 2221
E-mail Address: coe.alangilan@g.batstate-u.edu.ph | Website Address: http://www.batstate-u.edu.ph
else: #Any invalid input or choices will prompt you to try again.
print("Please pick from options 1-3 only.")
main()
If resistance value is less than zero: If the user did not pick from options 1-3:
Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Alangilan Campus
Golden Country Homes, Alangilan Batangas City, Batangas, Philippines 4200
Tel Nos.: (+63 43) 425-0139 local 2121 / 2221
E-mail Address: coe.alangilan@g.batstate-u.edu.ph | Website Address: http://www.batstate-u.edu.ph