Plz check my code

Hey can you plz check my code and write correct code for this I am a newbie so plz don’t judge

c= input(print(‘input A for Area P for perimeter:’))

number_1 = int(input('Please enter the first number: '))
number_2 = int(input('Please enter the second number: '))

if c == 'A':
    print('area is',number_1 * number_2)

if c == 'P':
    print('perimeter is',number_1 + number_2)

Firstly, there’s an extra print function in the first line:
c= input(print(‘input A for Area P for perimeter:’))
input function will already print the prompt you specify, so there’s no need to use print. So, this line should look like this:
c= input(‘input A for Area P for perimeter:’)

Secondly, your formula for perimeter is wrong. If you’re dealing with a rectangle, you need to sum up the lengths of all four sides, not two.

Thirdly, you could also improve how your code deals with invalid inputs. For example, if the user of your program types neither “P” nor “A”, your program will just exit silently without telling the user why.

2 Likes

Thank you so much sir for your help
I will surely improve
Thank you for the guidance

c=input(‘’’
select shape
1- square
2- rectangle
enter- ‘’‘)
if c== ‘1’:
r=input(’‘’
A- area
P- perimeter
enter- ‘’')
d=float(input('length - '))
if r==‘A’:
print ('area of square is ',d*d)
if r==‘P’:
print ('perimeter of square is ',d+d+d+d)
import sys
sys.exit()

if c== ‘2’:
m=input(‘’’
A- area
P- perimeter
enter- ‘’')
e=float(input('length- '))
f=float(input('breath- '))
if m==‘P’:
print (‘perimeter of rectangle is’,e+e+f+f)
if m==‘A’:
print (‘area of rectangle is’,e*f)

Square is working but rectangle is showing error plz check

You say that it’s showing an error, but you didn’t say what that error was. Please post the full traceback.

Also, please wrap any code in triple backticks to retain its formatting:

```
for i in range(3):
   print('Hello')
```
1 Like

select shape
1- square
2- rectangle
enter- 2
Traceback (most recent call last):
File “/data/user/0/com.kvassyu.coding.py/files/default.py”, line 12, in
if r==‘A’:
NameError: name ‘r’ is not defined

[Process completed (code 1) - press Enter]

I’m guessing that the indentation is incorrect, but I can’t be sure because of the messed-up formatting.