如果Elif Else链分类三角形(Python)

时间:2014-09-25 05:22:35

标签: python if-statement

a = input("Please Enter Side  A ") 
b = input("Please Enter Side  B") 
c = input("Please Enter Side  C ") 

d = a+b+c 

if d < (2*a) or d < (2*b) or d < (2*c): 
   print "Shame on you, that is not a triangle!" 
elif (a==b==c): 
   print "It's Equilateral"  
elif (a==b) or (a==c) or (b==c): 
   print "It's Isosceles"   

我有以下任务,我很难掌握。

  

让用户告诉你三角形的三个角度,以度,分和秒为单位。使用if-elif-else链对三角形进行分类:

     

计算三个角度的总和。如果角度的总和等于180°0'0“[180度,零分钟,零秒],则它是欧几里德三角形。如果角度的总和超过180°0'0”,则它不能是欧几里德三角形在一个平面上:它是“椭圆形的”,也许是在一个球体上,例如一个行星,就像一颗行星,就像一颗不起眼的太阳的小行星,在一个被称为“地球”的平庸星系的一个不起眼的角落里。如果角度的总和小于180°,则三角形必须是“双曲线”,在凹面上,这可能是我们宇宙的形状。 [为了额外的功劳,你可以通过绘制2条平行线来解决这个问题,每条方向至少有732亿光年,并确定这些线路是否曾经交叉过。]

     

此外,将三角形分类为:

     

等边:所有三个角度相等

     

等腰:两个且只有两个角度相等

     

Scalene:如果既不是等边也不是等腰

     

你的程序应该说“这是一个欧几里德斯特恩三角形”或“那是一个双曲线等边三角形”。您应该告诉用户三个角度的总DMS(度,分,秒)是多少。

我的问题和猜测是,我只需要包括elif else功能,这就是我迄今为止所拥有的功能。我试图添加角度而不是侧面的长度,但我得到一个错误。如果它们是等腰等边,如何将角度的测量值转换成?任何输入将不胜感激。非常感谢您的宝贵时间。

           (Deg)   (Min)   (Sec)
Angle A      29       0      30
Angle B      60      15      30
Angle C      90      44       0                

1 个答案:

答案 0 :(得分:1)

我只能给你一个样品。您需要自己编辑此程序以满足您的要求。

a = []
b = []
c = []
a[0] = float(input('Please enter degrees for a:'))
a[1] = float(input('Please enter minutes for a:'))
a[2] = float(input('Please enter seconds for a:'))
b[0] = float(input('Please enter degrees for b:'))
b[1] = float(input('Please enter minutes for b:'))
b[2] = float(input('Please enter seconds for b:'))
c[0] = float(input('Please enter degrees for c:'))
c[1] = float(input('Please enter minutes for c:'))
c[2] = float(input('Please enter seconds for c:'))


print 'Now for angle A, we have degrees: %f, minutes: %f, seconds: %f.' % (a[0], a[1], a[2])
print 'Now for angle B, we have degrees: %f, minutes: %f, seconds: %f.' % (b[0], b[1], b[2])
print 'Now for angle C, we have degrees: %f, minutes: %f, seconds: %f.' % (c[0], c[1], c[2])

a_in_de = a[0] + a[1]/60 + a[2]/60
b_in_de = b[0] + b[1]/60 + b[2]/60
c_in_de = c[0] + c[1]/60 + c[2]/60
summary = a_in_de + b_in_de + c_in_de
if summary == float(180):
    print "It's an Euclidean triangle"
elif summary > float(180):
    print "It's an elliptical."
elif summary < float(180):
    print "It's a hyperbolic."