返回列表 發帖

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]))
複製代碼

  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]}人")
複製代碼

TOP

  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]))
複製代碼

TOP

  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]}位")
複製代碼

TOP

list2=[19,56,35,55,6.46,54,48]
list1=["忠","孝","仁","愛","信","義","和","平"]
for i in range(0,8,1):
    print(f'五年{list2[i]}班有{list1[i]}人' )

TOP

  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]}人")
複製代碼

TOP

  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]}人")
複製代碼

TOP

  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]}人")
複製代碼

TOP

  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]))
複製代碼

TOP

  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]}人' )
複製代碼

TOP

  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]))
複製代碼

TOP

  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]))   
複製代碼

TOP

  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]}人")
複製代碼

TOP

  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]))
複製代碼

TOP

返回列表