2014-04-06 1 views
1
print "This is to find the area or perimeter of a rectangle " 
print "Do you want to find the area(a) or perimeter(p) of your rectangle?" 
a= raw_input(" I want to find the ") 
if raw_input = (a) 
     print "What is the length of the rectangle?" 
     b = int(raw_input("The length of the rectangle is ")) 
     print "What is the width of the rectangle?" 
     c = int(raw_input("The width of the rectangle is ")) 
     d = (2 * b) + (2 * c) 
     print d 
if raw_input = (p) 
     print "Got it. What is the length of your rectangle?" 
     x = int(raw_input("The length of the rectangle is ")) 
     print "What is the width of your rectangle?" 
     y = int(raw_input("The width of the rectangle is ")) 
     z = x * y 
     print z 

가 어떻게 a이 지역이며 p이 경계라고 말할 코드를 프로그램 할 수 경계하기 위해 경우?문이 지역을 찾아

+0

지역 점검 경계선과 경계선 검사 영역이 있습니까? –

+0

나는 무엇을 의미하는지 모르겠다. – user3502630

+0

[파이썬에서 문자열 형식] (https://docs.python.org/2/library/stdtypes.html#string-formatting-operations)도 찾고 계십니까? – miah

답변

1

수표를 틀리게하고 있습니다. 파이썬에서 =은 할당을 의미하는 반면 ==은 동등성 테스트입니다. 대신이 시도 : 이것은 홀수

print "This is to find the area or perimeter of a rectangle " 
print "Do you want to find the area(a) or perimeter(p) of your rectangle?" 
a= raw_input(" I want to find the ") 
if a=='a': 
    print "What is the length of the rectangle?" 
    b = int(raw_input("The length of the rectangle is ")) 
    print "What is the width of the rectangle?" 
    c = int(raw_input("THe width of the rectangle is ")) 
    d = b*c 
    print d 
elif a=='p': 
    print "Got it. What is the length of your rectangle?" 
    x = int(raw_input("The length of the rectangle is ")) 
    print "What is the width of your rectangle?" 
    y = int(raw_input("The width of the rectangle is ")) 
    z = 2*x+2*y 
    print z 
+0

'if' 문에 들여 쓰기가 잘못되었습니다. 그리고 당신은 여전히 ​​하나의 등호를 가지고 있습니다. 그리고 당신의 지역'if' 문은 경계를 검사하고, 주변 if 문은 영역을 검사합니다. :) –

2

, 당신은 raw_input() 뭔가 있는지 확인할 수 없습니다. 또한 동등성을 테스트하는 것은 ==이고, =을 할당하는 것입니다. 원하는 것은 다음과 같습니다.

print "This is to find the area or perimeter of a rectangle " 
print "Do you want to find the area(a) or perimeter(p) of your rectangle?" 
a= raw_input(" I want to find the ") 
if a=='p': 
     print "What is the length of the rectangle?" 
     b = int(raw_input("The length of the rectangle is ")) 
     print "What is the width of the rectangle?" 
     c = int(raw_input("THe width of the rectangle is ")) 
     d = (2 * b) + (2 * c) 
     print d 
elif a=='a': 
     print "Got it. What is the length of your rectangle?" 
     x = int(raw_input("The length of the rectangle is ")) 
     print "What is the width of your rectangle?" 
     y = int(raw_input("The width of the rectangle is ")) 
     z = x * y 
     print z 
+0

+1 좋은 잡기. 감사! 이에 따라 답변이 업데이트되었습니다. – sshashank124