Discuss / Python / 打卡打卡

打卡打卡

Topic source

小马

#1 Created at ... [Delete] [Delete and Lock User]

#请利用循环依次对list中

#的每个名字打印出Hello, xxx!:

# print('欢迎您来到廖老师的班级')

# print('班级名单如下:')

# L = ['Bart', 'Lisa', 'Adam']

# for classname in L:

#     names='hello,'+classname+'!'

#     print(names)

#练习

#break 提前结束循环

# n = 1

# while n <= 100:

#     if n > 10: # 当n = 11时,条件满足,执行break语句

#         break # break语句会结束当前循环

#     print(n)

#     n = n + 1

# print('END')

#continue 跳出当前的这次循环

n = 0

while n < 10:

    n = n + 1

    if n % 2 == 0: # 如果n是偶数,执行continue语句

        continue # continue语句会直接继续下一轮循环,后续的print()语句不会执行

    print(n)


  • 1

Reply