四边形和其他形状的周长

时间:2015-07-15 10:48:24

标签: python

所以今天在科学课上我想到为四边形的基本边界制作一个python脚本。将来以后我想扩展到圆形和其他形状,但我陷入了错误。请帮忙。

我的代码:

bList

https://repl.it/xHG

输出很时髦。如果print ("This is a program to find the perimeter of a quadrilateral. Input the length and breath and get the desired perimeter") len = input("What is the length?") bre = input("What is the breath?") length = len + len breath = bre + bre perimeter = length + breath print ("The perimeter of the quadrilateral is :" + perimeter) l=2则输出为b=1

另外,如何将其扩展为不同的形状?我正在考虑使用if和else选项2211然后执行循环代码if choice = circle然后执行三角形代码。有没有人有更好的主意?

1 个答案:

答案 0 :(得分:0)

请记住转换数据类型

print ("This is a program to find the perimeter of a quadrilateral. Input the length and breath and get the desired perimeter")
len = input("What is the length?")
bre = input("What is the breath?")
len=int(len)
bre=int(bre)
length = len + len
breath = bre + bre
perimeter = length + breath
print ("The perimeter of the quadrilateral is :" + str(perimeter))