close

請使用遞迴方式自定Function,將list中大於5
的資料加總
print sum([1, 7, 4, 6, 8, 2])  ===> 21

def sum(list):
    count=0
    if len(list)==0:
        return 0
    else:
        count=list.pop()
        if count>5:
            return  count+sum(list)
        else:
            return sum(list)
print sum([1,7,4,6,8,2])
------------------------------------------------------------------------------------
 

以下是洋基隊投手生涯數據,請依使用者所
需的資料排列法改變報表呈現方式。

                              W    L     ERA    SO
C-M Wang           49    18   3.75    240
Andy Pettitte      203  114   3.83   1853
Mariano Rivera    62    44    2.34   864



list=[["c-m-wang",49,18, 3.75,240],["Andy Pettitte",203,114, 3.83 ,1853],["Mariano Rivera",62,42,2.34,864]]

s = int(raw_input('sort type'))
tmplist = []
for i in range(0,3):
    for j in range(0,2-i):
        if list[j][s]> list[j+1][s]:
            tmplist = list[j+1]
            list[j+1] = list[j]
            list[j] = tmplist

for i in range(0,3):
    print list[i]

-----------------------------------------------------------------------------------------------------------------
  設計一函數,找出某字元在某字串中第一次出現的位置
例如:
Find(‘a’, ‘cocacola’)   ----> 4
Find(‘k’, ‘cocacola’)   ---->not found
/////////////////////////////////////////////////////////////////////////////////////////////////

設計一函數,找出某字元在某字串中第一次出現的位置


def kkk(str,str2):
    if len(str2)==0:
        print "not found"
    else:
       
        for i in str[i]:
            temp.append(i)

kkk('a','sfjishhjhza')


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 auraler 的頭像
    auraler

    熱狗和茄子的戀愛

    auraler 發表在 痞客邦 留言(0) 人氣()