標題:
for 迴圈 (三)
[打印本頁]
作者:
鄭繼威
時間:
2022-7-19 02:28
標題:
for 迴圈 (三)
#range(start,stop,step)
#range(1,6)->[1,2,3,4,5]
試宣告兩個串列,一個存放班級名稱,一個存放人數,搭配 for 迴圈顯示五年級各班人數,執行畫面如下:
list1=["忠","孝","仁","愛","信","義","和","平"]
list2=[28,27,27,26,28,29,30,27]
for i in range(8):
print("五年{}班有{}人".format(list1[i],list2[i]))
複製代碼
作者:
鄭繼威
時間:
2022-7-19 15:08
list1=["忠","孝","仁","愛","信","義","和","平"]
list2=[28,27,27,26,28,29,30,27]
#range(0,8)->[0...7]
for i in range(0,8):
print(f"五年{list1[i]}班有{list2[i]}人")
複製代碼
作者:
張晏齊
時間:
2022-7-19 15:13
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
list1=["忠","孝","仁","愛","信","義","和","平"]
list2=[28,27,27,26,28,29,30,27]
#range(0,8)->[0...7]
for i in range(0,8):
print(f"五年{list1[i]}班有{list2[i]}人")
複製代碼
作者:
盧宥熏
時間:
2022-7-19 15:13
list1=["忠","孝","仁","愛","信","義","和","平"]
list2=[28,27,27,26,28,29,30,27]
for i in range (0,8):
print(f"五年{list1[i]}班有{list2[i]}人")
複製代碼
作者:
陳羨芮
時間:
2022-7-19 15:14
list1=["忠","孝","仁","愛","信","義","和","平"]
list2=[28,27,27,26,28,29,30,27]
for i in range(8):
print(f"五年{list1[i]}班有{list2[i]}人")
複製代碼
作者:
盧宥廷
時間:
2022-7-19 15:15
list1=["忠","孝","仁","愛","信","義","和","平"]
list2=[28,27,27,26,28,29,30,27]
for i in range(0,8):
print(f"五年{list1[i]}班有{list2[i]}人")
複製代碼
作者:
李宥廷
時間:
2022-7-19 15:15
list1=b=["忠","孝","仁","愛","信","義","和","平"]
list2=c=[28,27,27,26,28,29,30,27]
for a in range(8):
print(f"五年{b[a]}有{c[a]}人")
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2