Board logo

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

作者: 鄭繼威    時間: 2023-7-10 16:00     標題: 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]))
複製代碼

作者: 董炫霆    時間: 2023-7-11 10:54

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

作者: 劉恆    時間: 2023-7-11 10:54

list1=["忠","孝","仁","愛","信","義","和","平"]
list2=[28,27,27,26,28,29,30,27]
for i in range(8):
    print("五年{}班有{}人".format(list1[i],list2[i]))
作者: 方昱安    時間: 2023-7-11 10:58

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

作者: 曾冠瑋    時間: 2023-7-11 11:02

list1=["忠","孝","仁","愛","信","義","和","平"]
list2=[28,27,27,26,28,29,30,27]
for i in range(8):
    print("五年{}班有{}人".format(list1[i],list2[i]))
作者: 黃柏翰    時間: 2023-7-11 11:04

list1=["忠","孝","仁","愛","信","義","和","平"]
list2=[22,33,44,55,12,19,18,12]
for i in range(8):
    print("五年{}班有{}人".format(list1[i],list2[i]))
作者: 歐陽霖    時間: 2023-7-11 11:07

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

作者: 呂宗晉    時間: 2023-8-3 11:05

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

作者: 高士涵    時間: 2023-8-3 11:06

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

作者: 盧承新    時間: 2023-8-3 11:07

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

作者: 矯博宇    時間: 2023-8-3 11:07

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

作者: 鄧維成    時間: 2023-8-3 11:07

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

作者: 得銓    時間: 2023-8-3 11:08

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

作者: 張子搴    時間: 2023-8-3 11:09

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

作者: 李逢翔    時間: 2023-8-3 11:10

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

作者: 盧芷萱    時間: 2023-8-3 11:11

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

作者: 張絜晰    時間: 2023-8-3 11:12

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

作者: 陳珺    時間: 2023-8-3 11:15

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




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