美文网首页
day08 作业 2018-07-25

day08 作业 2018-07-25

作者: LPP27149 | 来源:发表于2018-07-25 20:57 被阅读0次
    def invert(list0):  # 第一题
        return list0[::-1]
    
    def str_odd(str0):  # 第二题
        return str0[::2]
    
    is_leap_year = lambda year : year % 4 == 0 # 第三题
    
    
    def print_something(n,space=0):
        if n == 1:
            print(' '*space+'@')
            return None
        print_something(n-1,space+1)
        print(' '*space+'@'*(2*n-1))
    
    
    def front_two(list0):  # 第五题
        if len(list0):
            return list0[:2]
    
    
    def fibonacci10(n=10):  # 第六题
        if n == 1 or n == 2:
            return 1
        return fibonacci10(n-1) + fibonacci10(n-2)
    
    
    def average_max(list0):  # 第七题
        sum0 = 0
        for item in list0:
            sum0 += item
        return (sum0/len(list0)),max(list0)
    
    
    def odd_element(s):  # 第八题
        return list(s[1::2])
    
    
    print('第一题:', invert([1, 2, 3, 4, 5, 6, 7]), sep=' ')
    print('第二题:', str_odd([1, 2, 3, 4, 5, 6, 7]), sep=' ')
    print('第三题:', is_leap_year(2018), sep=' ')
    print('第四题:', sep=' ');print_something(4, space=0)
    print('第五题:', front_two([1, 2, 3, 4, 5, 6, 7]), sep=' ')
    print('第六题:', fibonacci10(), sep=' ')
    print('第七题:', average_max([1, 2, 3, 4, 5, 6, 7]), sep=' ')
    print('第八题:', odd_element((1, 2, 3, 4, 5, 6, 7)), sep=' ')
    


    第一题: [7, 6, 5, 4, 3, 2, 1]
    第二题: [1, 3, 5, 7]
    第三题: False
    第四题:
       @
      @@@
     @@@@@
    @@@@@@@
    第五题: [1, 2]
    第六题: 55
    第七题: (4.0, 7)
    第八题: [2, 4, 6]
    

    相关文章

      网友评论

          本文标题:day08 作业 2018-07-25

          本文链接:https://www.haomeiwen.com/subject/nqmmmftx.html