作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
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
是周长?
最佳答案
这很奇怪,您无法检查 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
关于python - 用于查找面积和周长的 If 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22889405/
我是一名优秀的程序员,十分优秀!