07 循环练习

for循环练习

# 练习题

# 1. for循环打印 “alex” 的每个元素: for > while

# 2. 请打印: 1 - 10
"""
 for i in range(1,11): # [1,2,3,4,5,6,7,8,9,10,11,12,14]  "12345678910"
     print(i)
"""

# 3. 请打印: 1 2 3 4 5 6 8 9 10
"""
for i in range(1,11):
    if i == 7:
        pass
    else:
        print(i)
"""


"""
users = ['李奇','奇利','张三','李子']
for i in users:
    print(i)
"""
"""
users = ['李奇','奇利','张三','李子']
for i in users:
    # 第一次循环:i=“李邵奇”
    print(i)
    for ele in i:
        print(ele)
"""

# 练习题:请通过for循环和数字计数器实现:users = ['李奇','奇利','张三','李子']
"""
    0 李奇
    1 利奇
    2 张三
    3 李子
"""
"""
# 方式一
users = ['李邵','利奇','张三','李森']
count = 0
for i in users:
    print(count,i)
    count += 1
"""
"""
# 方式二
users = ['李奇','利奇','张三','李森']
users_len = len(users) # 4
for index in range(0,users_len): # [0,1,2,3]
    print(index,users[index])  #users[index] 获取索引里面的值
"""
posted @ 2024-09-25 20:35  jhchena  阅读(3)  评论(0编辑  收藏  举报