Python error


#1

Hello everyone! I hope you all have a great weekend!
I have a trouble with this work. The output doesn’t make send when I apply the value.
Any help is great. Thank you so much!


#2

On something like this it is often simpler if we abstract away the simple functions.

from math import pi

def get_number():
  while True:
    try:
      return int(input("Enter a number: "))
    except ValueError:
      print ("Invalid input. Try again...")

def square():
    print ("Length of a side...")
    n = get_number()
    return "Square with side length {} has a perimeter of {} \
and an area of {}.".format(n, 4 * n, n ** 2)

def circle():
    print ("Length of radius...")
    r = get_number()
    return "Circle with radius length {} has a circumferance of {:f} \
and an area of {:f}.".format(r, 2 * pi * r, pi * r ** 2)

print (square())
print (circle())
Length of a side...
Enter a number:  5
Square with side length 5 has a perimeter of 20 and an area of 25.
Length of radius...
Enter a number:  5
Circle with radius length 5 has a circumferance of 31.415927 and an area of 78.539816.

https://repl.it/MQ7N

That’s three functions out of the way. You could fashion one to accept textual input, but if you are using numbers for menu items, then use get_number and test the value on return. Just as get_number uses an infinite loop, yours could also for this purpose.

Once you have lightened the load of your main program, the rest should fall into place.