Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE I NEED HELP WITH MY PYTHON PROGRAM!!!!!!!!!!!!!! I need help when users i

ID: 3931575 • Letter: P

Question

PLEASE I NEED HELP WITH MY PYTHON PROGRAM!!!!!!!!!!!!!!
I need help when users input 3 to calculate the area of the rectangle and trapezoid. So far I have caculated both
but, I dont know how to code the 3rd option when users wants to calculate both area.


Here is my code!

def f1(x):
return 5*x**4 + 3*x**3 - 10*x + 2
def f2(x):
return x**2 - 10
def f3(x):
return 40*x + 5
def f4(x):
return x**3
def f5(x):
return 20*x**2 + 10*x - 2


print("1 - 5x^4 + 3x^3 - 10x +2 ")
print("2 - x^2 -10 ")
print("3 - 40x +5 ")
print("4 - x^3 ")
print("5 - 20x^2 + 10x -2 ")
print("6 - quit ")
while True:
   try:
       function = int(input("Choose a function (1, 2, 3, 4, 5, 6): "))
       break
   except ValueError:
           print("Invalid function choice!")
if function == 6:
   exit()


while True:
   try:
       way = int(input("Would you like to calculate the area using rectangle, trapezoid, or both (1, 2, 3): "))
       break
   except ValueError:
       print("Invalid options!")
      
if way==1:
   while True:
       try:
           num = int(input("How many rectangles do you want?: "))
           break
       except ValueError:
           print("Wrong input for the rect!")

elif way==2:
   while True:
       try:
           num = int(input("How many trapezoids do you want?: "))
           break
       except ValueError:
           print("Wrong input for the trap! ")
elif way==3:
   while True:
       try:
           rec = int(input("How many rectangles do you want?: "))
           break
       except ValueError:
           print("Wrong input for the rect!")
   while True:
       try:
           trap = int(input("How many trapezoid do you want?: "))
           break
       except ValueError:
           print("Wrong input for the trap!")
while True:
   try:
       start = int(input("Please select a starting point: "))
       break
   except ValueError:
       print("Wrong input for the starting point!")
while True:
   try:
       end = int(input("Please select an ending point: "))
       break
   except ValueError:
       print("Wrong input for the ending point!")
f = 0
if way==1:
if function == 1:
for i in range(num+1):
x = start+i*(end-start)/num
f+=abs(f1(x)*(end-start)/num)
print("The area under the curve between", start, "and", end, "is", f)

elif function == 2:
for i in range(num+1):
x = start+i*(end-start)/num
f+=abs(f2(x)*(end-start)/num)
print("The area under the curve between", start, "and", end, "is", f)

elif function == 3:
for i in range(num+1):
x = start+i*(end-start)/num
f+=abs(f4(x)*(end-start)/num)
print("The area under the curve between", start, "and", end, "is", f)

elif function == 4:
for i in range(num+1):
x = start+i*(end-start)/num
f+=abs(f4(x)*(end-start)/num)
print("The area under the curve between", start, "and", end, "is", f)
elif function == 5:
for i in range(num+1):
x = start+i*(end-start)/num
f+=abs(f5(x)*(end-start)/num)
print("The area under the curve between", start, "and", end, "is", f)


elif way ==2:
if function == 1:
for i in range(num+1):
h = end-start
x1 = start + (i-1)*h/num
x2 = start + (i)*h/num
f += abs((h*(f1(x1) + f1(x2))/2.0)/num)
print ("The area under the curve between", start, "and", end, "is", f)

if function == 2:
for i in range(num+1):
h = end-start
x1 = start + (i-1)*h/num
x2 = start + (i)*h/num
f += ((h*(f2(x1) + f2(x2))/2.0)/num)
print ("The area under the curve between", start, "and", end, "is", f)

if function == 3:
for i in range(num+1):
h = end-start
x1 = start + (i-1)*h/num
x2 = start + (i)*h/num
f += abs((h*(f3(x1) + f3(x2))/2.0)/num)
print ("The area under the curve between", start, "and", end, "is", f)

if function == 4:
for i in range(num+1):
h = end-start
x1 = start + (i-1)*h/num
x2 = start + (i)*h/num
f += abs((h*(f4(x1) + f4(x2))/2.0)/num)
print ("The area under the curve between", start, "and", end, "is", f)

if function == 5:
for i in range(num+1):
h = end-start
x1 = start + (i-1)*h/num
x2 = start + (i)*h/num
f += abs((h*(f5(x1) + f5(x2))/2.0)/num)
print ("The area under the curve between", start, "and", end, "is", f)


elif way==3:
if function == 1:
for i in range(trap+1):
h = end-start
x1 = start + (i-1)*h/trap
x2 = start + (i)*h/trap
f += abs((h*(f1(x1) + f1(x2))/2.0)/trap)
print ("The area under the curve between", start, "and", end, "is", f)

if function == 2:
for i in range(trap+1):
h = end-start
x1 = start + (i-1)*h/trap
x2 = start + (i)*h/trap
f += ((h*(f2(x1) + f2(x2))/2.0)/trap)
print ("The area under the curve between", start, "and", end, "is", f)

if function == 3:
for i in range(trap+1):
h = end-start
x1 = start + (i-1)*h/trap
x2 = start + (i)*h/trap
f += abs((h*(f3(x1) + f3(x2))/2.0)/trap)
print ("The area under the curve between", start, "and", end, "is", f)

if function == 4:
for i in range(trap+1):
h = end-start
x1 = start + (i-1)*h/trap
x2 = start + (i)*h/trap
f += abs((h*(f4(x1) + f4(x2))/2.0)/trap)
print ("The area under the curve between", start, "and", end, "is", f)

if function == 5:
for i in range(trap+1):
h = end-start
x1 = start + (i-1)*h/trap
x2 = start + (i)*h/trap
f += abs((h*(f5(x1) + f5(x2))/2.0)/num)
print ("The area under the curve between", start, "and", end, "is", f)

elif way==3:
{
Needs to calculate both rectanlge and trapezoid for each function
}

Explanation / Answer

way = int(input("Would you like to calculate the area using rectangle, trapezoid, or both (1, 2, 3): "))
       break
   except ValueError:
       print("Invalid options!")
      
if way==1:
   while True:
       try:
           num = int(input("How many rectangles do you want?: "))
           break
       except ValueError:
           print("Wrong input for the rect!")

elif way==2:
   while True:
       try:
           num = int(input("How many trapezoids do you want?: "))
           break
       except ValueError:
           print("Wrong input for the trap! ")
elif way==3:
   while True:
       try:
           rec = int(input("How many rectangles do you want?: "))
           break
       except ValueError:
           print("Wrong input for the rect!")
   while True:
       try:
           trap = int(input("How many trapezoid do you want?: "))
           break
       except ValueError:
           print("Wrong input for the trap!")

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote