Python: writing a program to compute the area of a circle and square

Posted by user1672504 on Stack Overflow See other posts from Stack Overflow or by user1672504
Published on 2012-09-14T21:27:12Z Indexed on 2012/09/14 21:37 UTC
Read the original article Hit count: 287

I have a question with an assignment. I'm not sure how to write this program and I really need help! Could someone help me with this? This is the assignment: Write a program that asks the user to enter two values: an integer choice and a real number x. If choice is 1, compute and display the area of a circle of radius x. If choice is 2, compute and display the are of a square with sides of length x. If choice is neither 1, nor 2, will display the text Invalid choice.

Sample run:

Enter choice: 2

Enter x: 8

The area is: 64.0

Sample run:

Enter choice: 1

Enter x: 8

The area is: 201.06176

My attempt:

choice = input ('Enter Choice:')

choice_1 = int (choice)

if (choice_1==1): radius = (int)

print('Enter x:',radius)

pi = 3.14159
area = ( radius ** 2 ) * pi
print ( 'The Area is=' , area )

© Stack Overflow or respective owner

Related posts about python-3.x

Related posts about computer-science