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()
# 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()