# Formula to calculate Gain of pyramidal horn antenna
# Gain = ((4 * Pi * Area of Aperature)/(Wavelength**2)) * Aperture Efficiency
# Aperature Efficiency is between 0 and 1
# Use functions for top number, bottom number and final calculation
import math
print ("Formula to compute Gain of pyramidal horn antenna")
print ("The formula for watts is: Gain = ((4 * Pi * Area of Aperature)/(Wavelength**2)) * Aperture Efficiency")
# Define functions that will calculate the formula
# Calculate the top of the formula
def topofformula():
EnteredAreaOfAperature = input ("Enter the area of aperature in square meters: ")
# Convert to integer
AreaOfAperature = int(EnteredAreaOfAperature)
TopOfFormula = (4* math.pi * AreaOfAperature )
print("Top of formula is: ", TopOfFormula)
return TopOfFormula
# Calculate the bottom of the formula
def bottomofformula():
EnteredWavelength = input ("Enter the wavelength in meters: ")
# Convert to integer
Wavelength = float(EnteredWavelength)
BottomOfFormula = (Wavelength**2)
print("The bottom of formula is: ", BottomOfFormula)
return BottomOfFormula
# Use the top and bottom numbers to make final gain calculation
def calculatefinalformula(AperatureEfficiency):
TopNumber = topofformula()
BottomNumber = bottomofformula()
Gain = ((TopNumber/BottomNumber) * AperatureEfficiency)
return Gain
# Input the Aperture Efficiency
# Use while loop to make sure that the Aperture Efficiency is between 0 and 1
AperatureEfficiency = -1
while (AperatureEfficiency<0 or AperatureEfficiency>1):
EnteredAperatureEfficiency = input ("Enter the Aperature Efficiency (number between 0 and 1): ")
# Convert to float
AperatureEfficiency = float(EnteredAperatureEfficiency)
# Test to see if the number is between 0 and 1
if AperatureEfficiency<0:
print ("Your number is less than zero. Please enter a number between 0 and 1.")
elif AperatureEfficiency>1:
print ("Your number is greater than one. Please enter a number between 0 and 1..")
else:
print ("You entered: ", AperatureEfficiency)
# Place result from function into variable to print
GainToPrint = calculatefinalformula(AperatureEfficiency)
print ("The Gain in dB is: ", GainToPrint)