Board logo

標題: for 迴圈 (三) [打印本頁]

作者: 鄭繼威    時間: 2024-7-9 01:24     標題: for 迴圈 (三)

#range(start=0,stop,step=1)
#range(1,6)->[1,2,3,4,5]

#for i in list資料

試宣告兩個串列,一個存放班級名稱,一個存放人數,搭配 for 迴圈顯示五年級各班人數,執行畫面如下:

  1. list1=["忠","孝","仁","愛","信","義","和","平"]
  2. list2=[28,27,27,26,28,29,30,27]
  3. for i in range(8):
  4.     print("五年{}班有{}人".format(list1[i],list2[i]))
複製代碼

作者: 王適源    時間: 2024-7-9 11:38

  1. list1=["忠","孝","仁","愛","信","義","和","平"]

  2. list2=[28,27,27,26,28,29,30,27]

  3. for i in range(8):
  4.     print("六年{}班有{}人".format(list1[i],list2[i]))
複製代碼

作者: 曾煒峻    時間: 2024-7-9 11:38

  1. list1=["忠","孝","仁","愛","信","義","和","平"]
  2. list2=[28,27,27,26,28,29,30,27]

  3. for x in range(1,8,1):
  4.     print(f"五年{list1[x]}班總人數:{list2[x]}人")
複製代碼

作者: 宋品澄    時間: 2024-7-9 11:39

  1. list1=["忠","孝","仁","愛","信","義","和","平"]
  2. list2=[28,27,27,26,28,29,30,27]
  3. for i in range(1,8,1):
  4.     print("五年{}班有{}人".format(list1[i],list2[i]))
複製代碼

作者: 李秉叡    時間: 2024-7-9 11:39

  1. list1=["忠","孝","仁","愛","信","義","和","平"]
  2. list2=[28,27,27,26,28,29,30,27]

  3. for i in range(8):
  4.     print("六年{}班有{}人".format(list1[i],list2[i]))   
複製代碼

作者: 朱宥愷    時間: 2024-7-9 11:41

  1. list1=["忠","孝","仁","愛","信","義","和","平"]
  2. list2=[28,27,27,26,28,29,30,27]
  3. for i in range(0,8,1):
  4.     print(f'五年{list1[i]}班有{list2[i]}人' )
複製代碼

作者: 林明漳    時間: 2024-7-9 11:41

  1. list1=["忠","孝","仁","愛","信","義","和","平"]
  2. list2=[22,23,24,25,26,27,38,29]
  3. for i in range(8):
  4.     print("五年{}班有{}人".format(list1[i],list2[i]))
複製代碼

作者: 蔡文霖    時間: 2024-7-9 11:42

  1. list1=["忠","孝","仁","愛","信","義","和","平"]
  2. list2=[28,27,27,26,28,29,30,27]
  3. for i in range(0,8,1)  :
  4.     print(f"五年{list1[i]}有{list2[i]}人")
複製代碼

作者: 姚宇孟    時間: 2024-7-9 11:42

  1. list=["忠","孝","仁","愛","信","義","和","平"]
  2. list2=[28,27,27,26,28,29,30,27]
  3. for i in range(0,8):
  4.     print(f"五年{list[i]}班有{list2[i]}人")
複製代碼

作者: 李秉叡    時間: 2024-7-9 11:43

  1. list1=["忠","孝","仁","愛","信","義","和","平"]
  2. list2=[28,27,27,26,28,29,30,27]

  3. for i in range(8):
  4.     print("六年{}班有{}人".format(list1[i],list2[i]))   
  5.         
  6. for i in range(8):
  7.     print(f"六年{list1[i]}班有{list2[i]}人")
複製代碼

作者: 古家全    時間: 2024-7-9 11:44

list2=[19,56,35,55,6.46,54,48]
list1=["忠","孝","仁","愛","信","義","和","平"]
for i in range(0,8,1):
    print(f'五年{list2[i]}班有{list1[i]}人' )
作者: 陳皇澐    時間: 2024-7-9 11:44

  1. list1=["忠","孝","仁","愛","信","義","和","平"]
  2. list2=[28,27,27,26,28,29,30,27]
  3. for b in range(1,8,1):
  4.     print(f"五年{list1[i]}班有{list2[i]}位")
複製代碼

作者: 黃裕恩    時間: 2024-7-9 11:46

  1. list1=["忠","孝","仁","愛","信","義","和","平"]
  2. list2=[28,27,27,26,28,29,30,27]
  3. for i in range(8):
  4.     print("五年{}班有{}人".format(list1[i],list2[i]))
複製代碼

作者: 李承燁    時間: 2024-7-9 11:46

  1. list=["忠","孝","仁","愛","信","義","和","平"]
  2. listn=[28,27,27,26,28,29,30,27]

  3. for i in range(8):
  4.     print(f"五年{list[i]}班共有{listn[i]}人")
複製代碼

作者: 奕樺    時間: 2025-1-24 10:43

  1. a=["忠","孝","仁","愛","信","義","和","平"]
  2. b=[28,27,27,26,28,29,30,27]
  3. for i in range(8):
  4.     print("五年{}班有{}人".format(a[i],b[i]))
複製代碼

作者: 黃煜翔    時間: 2025-1-24 11:01

list_1 = ["忠","孝","仁","愛","信","義","和","平"]
list_2 = [28,27,27,26,28,29,30,27]
for i in range(8):
    print("五年{}班有{}人".format(list_1[i],list_2[i]))
作者: 王奕勝    時間: 2025-1-24 11:07

  1. a=["忠","孝","仁","愛","信","義","和","平"]
  2. b=[28,27,27,26,28,29,30,27]
  3. for i in range(8):
  4.     print("五年{}班有{}人".format(a[i],b[i]))
複製代碼

作者: 吳拓言    時間: 2025-1-24 11:08

list1=["忠","孝","仁","愛","信","義","和","平"]
list2=[30,32,27,25,34,31,30,27]
for i in range(8):
    print("五年{}班有{}人".format(list1[i],list2[i]))
作者: 林彥翰    時間: 2025-1-24 11:08

回復 1# 鄭繼威


    list1=["忠","孝","仁","愛","信","義","和","平"]
list2=[28,27,27,26,28,29,30,27]
for i in range(8):
    print("五年{}班有{}人".format(list1,list2))
作者: 葉紫薰    時間: 2025-1-24 11:09

回復 1# 鄭繼威


    a = ['忠','孝','仁','愛','義','和','平']
b = [28,27,27,26,26,28,29,30,27]

for i in range(len(a)):
    print('五年',a,'班有',b,'人',sep='')
作者: 林佩萱    時間: 2025-1-24 11:16

本帖最後由 林佩萱 於 2025-1-24 11:22 編輯
  1. list1=["忠","孝","仁","愛","信","義","和","平"]
  2. list2=[28,27,27,26,28,29,30,27]
  3. for i in range(8):
  4.     print("五年{}班有{}人".format(list1[i],list2[i]))
複製代碼

作者: 黃煜凱    時間: 2025-1-24 11:16

for i,j in zip(list1,list2):
    print('五年',i,'班有',j,'人',sep = '')
作者: 黃煜凱    時間: 2025-1-24 11:20

list1=["忠","孝","仁","愛","信","義","和","平"]
list2=[28,27,27,26,28,29,30,27]
list3=[93,95,92,89,97,90,91,93]

for i,j,k in zip(list1,list2,list3):
    print('五年',i,'班有',j,'人,班上月考平均成績是',k,'分',sep = '')
作者: 林佩萱    時間: 2025-1-24 11:22

list1=["忠","孝","仁","愛","信","義","和","平"]
list2=[28,27,27,26,28,29,30,27]
for i in range(8):
    print("五年{}班有{}人".format(list1[i],list2[i]))
作者: 陳竹煖    時間: 2025-1-24 11:22

  1. list1=["忠","孝","仁","愛","信","義","和","平"]
  2. list2=[28,27,27,26,28,29,30,27]
  3. for i in range(len(list1)):
  4.     print("五年%s班有%d人"%(list1[i],list2[i]))
複製代碼

作者: 江珮慈    時間: 2025-1-24 11:31

回復 1# 鄭繼威


    list1=["忠","孝","仁","愛","信","義","和","平"]
list2=[28,27,27,26,28,29,30,27]
for i ,j in zip(list1,list2):
    print("五年",i,"班有",j,'人',sep='')
作者: 林佩萱    時間: 2025-1-24 13:44

a = ['忠','孝','仁','愛','義','和','平']
b = [28,27,27,26,26,28,29,30,27]

for i in range(len(a)):
    print('五年',a,'班有',b,'人',sep='')




歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/) Powered by Discuz! 7.2