python基础学习4- 控制语句

import sys

# if控制语句
name = 'Alice'
age = 10
if name == 'Alice':
    print('Hi,Alice')
elif age < 12:
    print('Not Alice')
else:
    print('Who')

# while 控制块
while True:
    print('Who are you?')
    nm = input()
    if nm != 'Joe':
        continue
    print('Hello Joe, password ? ')
    password = input()
    if password == '888888':
        break
    if password == 'exit':
        sys.exit()
print('Access granted!')

# for 控制块
total = 0
for num in range(101):
    total = total + num     
print(total)

# 嵌套循环 - 九九乘法表
for i in range(1,10):
    for j in range(1,10):
        print('{} * {} = {}'.format(i,j,i*j))

# 小程序:密码错误3次禁止输入
password_list = ['*#*#','12345']
def account_login():
    tries = 3
    while tries > 0:
        password = input('Password:')
        password_correct = password==password_list[-1]
        password_reset = password==password_list[0]
        if password_correct:
            print('Login success!')
            break
        elif password_reset:
            new_password = input('Enter a new password:')
            password_list.append(new_password)
            print('Password has changed successfully!')
            account_login()
        else:
            print('Wrong password or invalid input!')
            tries = tries - 1
            print(tries,' times left')
    else:
        print('Your account has been suspended')
account_login()


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值