三种方式循环打印1-100的值


#方式一:
x=0

def task():
    count=0
    while True:

        global x
        x=x + 1
        print(x)
        
        count=count + 1
        if count == 100:
            break
task()
#打印结果就是:1-100


#方式二
x=0
count=0
def task():
    
    global x,count
    x = x + 1
    print(x)
    
    count = count + 1
    if count == 100:
        break
task()
#打印结果是:1-100


#方式三

x=0

def task():
    
    for i in range(1,101):
        global x
        x = x + 1
        print(x)

task()

#打印结果是:1-100
























原文地址:https://www.cnblogs.com/ludundun/p/11544892.html