# Unwanted function outputs

Does anyone know how to get rid of the “None” and “Sorry, invalid input” after the solution.
My code:

def area_of_triangle():
b = input("Base: ")
h = input("Height: ")
area =  0.5 * float(b) * float(h)
print("The area of the triangle is " + str(area) + ".")

def area_of_square():
l = input("Length: ")
w = input("Width: ")
area = int(l) * int(w)
print("The area of the square is " + str(area) + ".")

def area_of_circle():
area = 3.14159 * float(r) ** 2
print("The area of the cirle is " + str(area) + ".")

def area_of_trap():
a = input("Base 1: ")
b = input("Base 2: ")
h = input("Height: ")
area = 0.5 * (float(a) + float(b)) * float(h)
print("The area of the trapeziod is " + str(area) + ".")

formula = input("Please type the equation you would like to do. If you dont know type help. ")
if formula == "triangle":
print(area_of_triangle())
if formula == "square":
print(area_of_square())
if formula == "circle":
print(area_of_circle())
if formula == "trapezoid":
print(area_of_trap())
if formula == "help":
print("To find the area of your shape in lowercase. Shapes: Triangle, square, circle, and trapezoid.")
else:
print("Sorry, invalid input.")

Output:

Simple… Don’t print in the function. Call the function, return a value, then print the return at the caller.

If we look at the code, you are printing at the caller, so change those print statements (in the functions) to return statements.

How do I call the function through the if statement?

You are calling the functions.

if formula == "triangle":
print(area_of_triangle())
#                        caller
1 Like

you might need to change the ifs after after the first one to elifs
otherwise it would do

print("Sorry, invalid input.")

whenever formula (from the input) is not "help"