gpt4 book ai didi

python - 用于查找面积和周长的 If 语句

转载 作者:行者123 更新时间:2023-11-30 23:25:41 24 4
gpt4 key购买 nike

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com