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.
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
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