回覆列表
  • 1 # 使用者5147634925370

    high = 100

    n = 10

    high_all = 0 #第n次落地時走過的長度

    high_each = 0 #每次落地的高度

    def ball_lands(n):

    global high_all, high_each, high

    #小球第一次落地時

    if n == 0:

    high_each = high

    high_all += high_each

    #print("1", high_each, high_all)

    return high_each

    #從小球第n次落地往前推

    high_each = high * (1 / 2) ** n

    print(u"第%d次小球彈起的高度為:%.2f" %(n, high_each))

    high_all += high_each * 2

    #print("2", high_each, high_all)

    ball_lands(n - 1)

    ball_lands(n)

    print(u"小球落地%d次,共經過%.2f米。" % (n,high_all))

  • 中秋節和大豐收的關聯?
  • NBA召開緊急會議!矛頭直指小卡和詹姆斯,28支球隊老闆抗議肖華表不滿,你如何評價?