python之自练习小程序(循环)

# 编写者:songwei
# 功能:使用while循环输出1到10
i = 0
list = [1,2,3,4,5,6,7,8,9,10]
while i<10:
    print(list[i])
    i+=1

# 功能:求1-100的所有数的和
sum = 0
for i in range(1,101):
    sum+=i
print("1-100之间的所有数的和 = %d" %sum)

# 功能:输出1-100内的所有奇数

for i in range(1,101,2):
    print(i)


# 功能:输出1-100内的所有偶数

for i in range(2,101,2):
    print(i)


# 功能:求1-2+3-4+5 ... 99的所有数的和
number = 0
sum = 0
for i in range(1,100):
    number=number+1
    if number%2 == 0:
        i = -i
    sum+=i
print(sum)

# 功能:用户登录(三次机会尝试)

name = "songwei"
password = "123"
i = 1
while i<=3:
    name1 = input("请输入您的用户名: ")
    password1 = input("请输入您的密码: ")
    i+=1

    if name == name1 and password == password1:
        print("你真的好牛逼")
        print("==========")
        print("登陆成功")
        break
    else:
        print("您还剩下 %d 次机会" %(4-i))
        t = 4-i
    if t == 0:
        print("你就知道瞎几把敲")
        break














你可能感兴趣的:(人生苦短,我用Python)