2016年9月17日 星期六

程式集訓 M90H023: 平面幾何:三角形重心


#coding=utf8

#程式集訓 M90H023: 平面幾何:三角形重心
'''
    M90H023: 平面幾何:三角形重心
'''
initial_value = 0
list_length = 6
sample_list1 = [initial_value]*list_length
i=0
j=0
while i<=2:
    while True:
      try:
        print("請輸入第",i+1,end="")
        m1,m2=(input("點(x,y)的x值及y值: (y=999 離開) :  ").split())
        m1=float(m1)
        m2=float(m2)
        if (m1 >= 0  and m2 >=0):
            break     
        else:
            print ('這是不合法的輸入.  請再輸入一次...')
            continue            
      except ValueError:
         print ('這是不合法的輸入.  請再輸入一次...')
         continue
    i=i+1
    sample_list1[j]=float(m1)
    j=j+1
    sample_list1[j]=float(m2)
    j=j+1
    print(sample_list1)
  
x= (sample_list1[0]+sample_list1[2]+sample_list1[4])/3
y= (sample_list1[1]+sample_list1[3]+sample_list1[5])/3
print("重心為(",'{:6.2f}'.format(x),"),(",'{:6.2f}'.format(y),")")
#=========================================

     

================= RESTART: D:/程式語言 Python 入門/程式集訓/M90H023.py =================
請輸入第 1點(x,y)的x值及y值: (y=999 離開) :  12 34
[12.0, 34.0, 0, 0, 0, 0]
請輸入第 2點(x,y)的x值及y值: (y=999 離開) :  23.9 23.5
[12.0, 34.0, 23.9, 23.5, 0, 0]
請輸入第 3點(x,y)的x值及y值: (y=999 離開) :  9.8 7.6
[12.0, 34.0, 23.9, 23.5, 9.8, 7.6]
重心為(  15.23 ),(  21.70 )
>>> 

沒有留言:

張貼留言

Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --3

  Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --3 AngularJS 實例 <!DOCTYPE html> <html> <head> <meta charse...