返回列表 發帖

for 迴圈 (三)

本帖最後由 鄭繼威 於 2023-7-11 10:25 編輯

#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=[1,2,3,4,5,6,7,8]
  2. list2=["仁","義","禮","智","信","忠","孝","和"]
  3. for i in range(8):
  4.     print("國一{}班有{}人".format(list2[i],list[i]))   
複製代碼

TOP

list1=["忠","孝","仁","愛","信","義","和","平"]
list2=[28,27,27,26,28,29,30,27]
for i in range(8):
    print("五年{}班有{}人".format(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(f"七年{list1[i]}班有{list2[i]}個人")
複製代碼

TOP

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

TOP

list1=["忠","孝","仁","愛","信","義","和","平"]
list2=[22,33,44,55,12,19,18,12]
for i in range(8):
    print("五年{}班有{}人".format(list1[i],list2[i]))

TOP

  1. list3=["和","平","誠","信","敬","業","樂","群" ]
  2. list4=[60,80,65,40,87,96,33,100]
  3. for i in list3:
  4.     print(i,end=" ")
  5. print()
  6. print()
  7. for j in range(8):
  8.     print(f"六年{list3[j]}班平均分數為{list4[j]}分")

  9. list4.sort(reverse=True)
  10. for k in range(1,9):
  11.     print(f"第{k}名考{list4[k-1]}分")
複製代碼

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 i in range(0,8):
  4.     print(f'五年{list1[i]}班有{list2[i]}人')
複製代碼

TOP

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

  3. for i in range(0,8):
  4.     print(f"五年{a[i]}班有{b[i]}人")
複製代碼

TOP

  1. a=["忠","孝","仁","愛","信","義","和","平"]
  2. b=[23,26,25,19,30,26,27,31,]
  3. for i in range(8):
  4.    print("六年",a[i],"班有",b[i],"人",sep="")
複製代碼

TOP

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

TOP

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

TOP

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

TOP

  1. list=["a","b","c","d","e","f","g","h"]
  2. list1=[20,31,27,30,29,33,26,28]
  3. for i in range(8):
  4.     print("There are {} students in Class {}.".format(list1[i],list[i]))
複製代碼
Attention Seeker </3

TOP

list1=["忠","孝","仁","愛","信","義","和","平"]
list2=[28,27,27,26,28,29,30,27]
for i in range0,8:
    print(f"五年{list1[i]}班有{list2[i]}人")

TOP

返回列表