列表习题
欲将4个字的桥名找出来,组成一个新的列表。bridge=list(["海津大桥","广场桥","解放桥","大沽桥","赤峰桥","保定桥","直沽桥","富民桥","金刚桥","金汤桥","北安桥","狮子林桥","永乐桥","大光明侨","刘庄浮桥","国泰桥"])
bridge_4=0
for i in range (len(bridge)) :
if bridge % 4 ==0 :
bridge_4.append(bridge)
print(bridge_4)
运行程序后,报错呀 ?
bridge=list(["海津大桥","广场桥","解放桥","大沽桥","赤峰桥","保定桥","直沽桥","富民桥","金刚桥","金汤桥","北安桥","狮子林桥","永乐桥","大光明侨","刘庄浮桥","国泰桥"])
bridge_4=[]
for i in range (len(bridge)) :
if len(bridge) % 4 ==0 :
bridge_4.append(bridge)
print(bridge_4) bridge=list(["海津大桥","广场桥","解放桥","大沽桥","赤峰桥","保定桥","直沽桥","富民桥","金刚桥","金汤桥","北安桥","狮子林桥","永乐桥","大光明侨","刘庄浮桥","国泰桥"])
bridge_4=[]
for i in bridge :
if len(i) % 4 ==0 :
bridge_4.append(i)
print(bridge_4)
页:
[1]