Python小练习(萌新)

版权声明:转载注明出处 https://blog.csdn.net/AtlanSI/article/details/81416773

1.输出1 2 3 4 5 6 8 9 10

i = 0
while i < 10:
    i += 1
    if i == 7:continue
    print(i)

2. 求出1-100之间的所有奇数

i = 0
while i <= 100:
    i += 1
    if (i % 2 ) == 0:continue
    print(i)

3.求出1-100之间的所有偶数

i = 0
while i <= 100:
    i += 1
    if (i % 2) == 0:print(i)
    continue

4.算出1-2+3+4+5+6....+99的值

i = 1
sum = 0
while i <= 99:
    sum += i
    i += 1
    if i == 2:
        sum = sum - i
        i = 3
print(sum)

5.模拟用户登录(最多三次机会)

i = 1
while i <= 3:
    user_name = input('请输入用户名:')
    o = 1
    if user_name == 'zp':
        while o <= 3:
            user_pass = input('请输入密码:')
            if user_pass == '123':
                print('登陆成功')
                exit()
            else:
                o += 1
                if o > 3:exit()
    else:
        i += 1
        continue

猜你喜欢

转载自blog.csdn.net/AtlanSI/article/details/81416773
今日推荐