dragov 发表于 2021-10-11 15:06:01

列表习题

欲将4个字的桥名找出来,组成一个新的列表。

bridge=list(["海津大桥","广场桥","解放桥","大沽桥","赤峰桥","保定桥","直沽桥","富民桥","金刚桥","金汤桥","北安桥","狮子林桥","永乐桥","大光明侨","刘庄浮桥","国泰桥"])
bridge_4=0
for i in range (len(bridge)) :
    if bridge % 4 ==0 :
      bridge_4.append(bridge)
print(bridge_4)

运行程序后,报错呀 ?

冬雪雪冬 发表于 2021-10-11 15:14:30

bridge=list(["海津大桥","广场桥","解放桥","大沽桥","赤峰桥","保定桥","直沽桥","富民桥","金刚桥","金汤桥","北安桥","狮子林桥","永乐桥","大光明侨","刘庄浮桥","国泰桥"])
bridge_4=[]
for i in range (len(bridge)) :
    if len(bridge) % 4 ==0 :
      bridge_4.append(bridge)
print(bridge_4)

冬雪雪冬 发表于 2021-10-11 15:15:28

bridge=list(["海津大桥","广场桥","解放桥","大沽桥","赤峰桥","保定桥","直沽桥","富民桥","金刚桥","金汤桥","北安桥","狮子林桥","永乐桥","大光明侨","刘庄浮桥","国泰桥"])
bridge_4=[]
for i in bridge :
    if len(i) % 4 ==0 :
      bridge_4.append(i)
print(bridge_4)
页: [1]
查看完整版本: 列表习题