0

Ok, so I have been trying to learn Python 2.7 for a couple days now, and so I was practicing writing programs for fun. I was trying to write a program that would find the area of a circle based on the radius someone inputs into it. here is the code I wrote:

print "Use this program to recieve the area of any circle you want!"
def area(n):
    if n > 0:
        return float(n) ** 2 * 3.14
    else:
        print "Needs to be a positive number"
n = raw_input("What's the radius? ")
print area(n)

The code looks like it would work, which it does to an extent. If I input a number into it, it does find the area of the circle for me! But, I wanted the program to say "Needs to be a positive number" if someone inputs a number less than or equal to 0. It doesn't do that for some reason! Instead, if I input 0, it will say the area is 0. And, if I input a negative number, it gives the area of a circle with the radius of the absolute value of the negative number. So what am I doing wrong with my code?

Eli
  • 31
  • 5

0 Answers0