返回列表 發帖

for 迴圈 (一)

本帖最後由 鄭繼威 於 2023-8-3 10:35 編輯


#for i in [list的資料型態]

#range(start=0,stop,step=1)

#range(1,6)->[1,2,3,4,5]
#range(5)->[0,1,2,3,4]
#range(1,5)->[1,2,3,4]
#range(1,5,2)->[1,3]


直向顯示第1名~第5名

  1. for i in range(1,6):
  2.     print("第",i,"名")
複製代碼

for i in range(0,101,a):
   print(f"第{i}名")

TOP

  1. for i in range(1,77,1):
  2.     print("第",i,"名")
複製代碼

TOP

  1. list=[1,2,3,4,5,6]
  2. for i in range(1,6):
  3.     print(f"第{i}名")
複製代碼

TOP

  1. for i in range(1,6):
  2.     print("第",i,"名")
複製代碼

TOP

  1. for i in range(1,6):
  2.     print(f"第{i}名!")
複製代碼
Attention Seeker </3

TOP

  1. for i in range(1,6):
  2.     print(f"地{i}名")
複製代碼

TOP

  1. for i in range(1,4):
  2.     print("第",i,"名")
複製代碼

TOP

  1. for i in range(1,51):
  2.     print(i)
  3. for i in range(2,101,2):
  4.     print(i)
  5. for i in range(1,6):
  6.     print(f"第{i}名")
複製代碼

TOP

  1. for i in range(1,6):
  2.     print(f"第{i}名")
複製代碼

TOP

  1. for i in range(1,6):
  2.     print(f"第{i}名")
複製代碼

TOP

  1. for i in range(1,6):
  2. print("第",i,"名")
複製代碼

TOP

#range(start=0,stop,step=1)
range(1,6)[1,2,3,4,5]
list2:[11,25,32,-50,-3,12]


#for i in list
for i in list2:
    print (i)
    print()
    for i in range(10):
        print(1)

TOP

  1. listC=[6,-45,45,-45,69,12,47]
  2. for i in listC:
  3.     print(i)
  4.    
  5. print("==========")
  6.    
  7. for i in range(1,50,2):
  8.     print(i)

  9. print("==========")

  10. for i in range(1,6):
  11.     print("第",i,"名")
複製代碼

TOP

本帖最後由 曾冠瑋 於 2023-7-11 10:32 編輯

list2=[11,25,-36,41.-26,15]
for i in list2:
    print(i)
for i in range(0,10,2):
    print(i)
for i in range(1,6,):
    print(i)

TOP

  1. for i in range(1,6,1):
  2.     print(f"第{i}名")
複製代碼

TOP

  1. for i in range(1,6):
  2.     print("第",i,"名")      
複製代碼

TOP

返回列表