Design a Python program by utilising from lists to define the number of generators n
QUESTION
PYTHON PROGRAMMING:
Design a Python program to compute and display the average output power of n number of generators, the lowest output power, and the highest output power. Read below.
Assume a hospital, which serves a rural area in Iraq, is fed continuously by a group of diesel engine-driven permanent magnet synchronous generators. The real electric output power of a synchronous generator can be expressed in line quantities as
Pout=3–√VLILcosθPout=3VLILcosθ
where VL and IL are the magnitudes of line voltage and current, while cosθ stands for power factor.
Design a Python program by utilizing from lists to define the number of generators n at first, then compute and display the average output power of n number of generators, the lowest output power, and the highest output power (in kW) respectively by taking into account the following considerations:
The line voltage VL shall be declared as a global constant and corresponds to 0.4 kV.
n, IL (in A), and θ (in ◦) values shall be entered by the user.
The conditions for
n ≥ 1,
IL > 0,
35◦ ≤ θ ≤ 40◦
shall be validated against erroneous entries.
SUMMARY
The number of generators is taken as input along with IL and theta values for each generator. The power is calculated for each of these generators. The average power and the total power are also calculated. Then the highest and lowest powers of the generators are printed as output to the console.
EXPLANATION
Initially, a variable ‘vl’ is declared and assigned with a voltage of 0.4 kV. This variable is made global. The number of generators ‘n’ is taken. A loop is inserted (which is iterated from 0 to n-1) to get the values of ‘il’ and theta for each iteration. Then the pout value is calculated for each of these iterations and is added to the sum of powers. The lowest power and highest power variables are updated at each time i.e each iteration. Finally, the average power is calculated and printed as output along with the lowest and highest power of the generators.
CODE
import math # avoiding floating-point error from decimal import * # global value of VL vl=0.4 # avoiding erraneous entries try: # to get number of generators n=int(input("Enter n: ")) s=0 l=999999 h=0 # to calculate average power # to find the lowest and highest powers for i in range(n): il=float(input("Enter IL: ")) theta=int(input("Enter theta: ")) pout=round(Decimal(str(vl*il*math.cos(theta*(math.pi/180)))),8) # finding the lowest power if l>pout: l=pout # finding the highest power if h<pout: h=pout s+=pout avg=s/n # printing the output print("Average output power:",avg) print("Lowest output power:",l) print("Highest output power:",h) except Exception as e: raise e
OUTPUT
Also Read, design, and implement (i.e write a program) an algorithm that adds two polynomials such as.