Board logo

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

作者: 鄭繼威    時間: 2024-1-24 16:05     標題: 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-1-25 11:49

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

作者: 李承睿    時間: 2024-1-25 11:51

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

作者: 鄭傳諭    時間: 2024-1-25 11:53

  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-1-25 11:53

  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-1-25 11:54

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

作者: 鄧塏諺    時間: 2024-1-25 11:55

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

作者: 劉乙頡    時間: 2024-1-25 11:55

list=[1,2,3]
list=[一,二,三]
for i in range(3):
    print(5-{}have{}people
作者: 張桔熙    時間: 2024-1-25 11:56

  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-1-25 11:57

  1. a1=['1','2','3','4','5','6','7','8',]
  2. a2=[21,23,19,22,25,23,21,24]
  3. for in range(8):
  4.     print('五年{}班有{}人'.format(a1[i],a2[i]))
複製代碼

作者: 劉娀德    時間: 2024-1-25 11:57

  1. peo=[2,3,4,2,4,3]
  2. grp=["一","二","三","四","五","六"]
  3. for i in range(6):
  4.     print("Group{}has{}people".format(grp[i],peo[i]))
複製代碼

作者: 劉乙頡    時間: 2024-1-25 12:29

list=[1,2,3]
list=[一,二,三]
for i in range(3):
    print(5-{}have{}people(list1[i],list2[i])
作者: 蘇宥駥    時間: 2024-1-25 12:30

s1=["甲","乙","丙","丁","戊","己","庚","辛"]
s2=[38,37,39,45,27,25,24,23]
for i in range(8):
    print("五年{}班有{}人".format(a1[i],a2[i]))




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