高级编程技术第五次作业、

时间:2021-11-21 21:58:14

5-6 人生的不同阶段

ages = [1, 2, 4, 13, 20, 65]
for age in ages:
	if age < 2:
		print('He is a baby.')
	elif age < 4:
		print('He is learing to walk.')
	elif age < 13:
		print('He is a child.')
	elif age < 20:
		print('He is a teenager.')
	elif age < 65:
		print('He is a adult.')
	else:
		print('He is a old man.')

5-8 以特殊方式跟管理员打招呼

users = ['user_1', 'admin', 'user_2', 'user_3', 'User_4']
for user in users:
	if(user == 'admin'):
		print('Hello admin, would you like to see a status report?')
	else:
		print('Hello ' + user + ', thank you for logging in again.')

5-10 检查用户名

current_users = ['USER_1', 'USER_2', 'USER_3', 'USER_4', 'USER_5']
current_users = ' '.join(current_users).title().split()
new_users = ['user_1', 'new_user_1', 'user_2', 'new_user_2', 'new_user_3']
for user in new_users:
	if(user.title() in current_users):
		print('You need to input another user.')
	else:
		print('This name is not used')

5-11 序数

numbers = range(1, 10)
for number in numbers:
	if number == 1:
		print(str(number) + 'st')
	elif number == 2:
		print(str(number) + 'nd')
	elif number == 3:
		print(str(number) + 'rd')
	else:
		print(str(number) + 'th')