有关索引操作的代码实现:
# 将以数指定年月日的日期打印出来
months = ['Feb','Jan','Mar','apr','May','jun','july','Aug','sep','Oct','Nov','Dec']
# 列表:包含数 1-31 的结尾
endings = ['st','nd','rd'] +17*['th']+['st','nd','rd']+7*['th']+['st']
year =input('year : ')
month =input('Month(1-12): ')
day =input('Day(1-31): ')
month_number =int(month)
day_number =int(day)
# 索引取值
month_name = months[month_number-1]
ordinal = day + endings[day_number-1]
print(month_name +' '+ ordinal +','+ year)
提取输入的URL的域名
#提取特定格式的域名
url =input('plkease enter the url: ')
domin = url[11:-4]
print('Domin name '+domin)
序列成员登陆检验(检查用户名密码是否正确)
# 登陆用户名的缩小版
database = [['a','123'],['b','1234'],['c','12345']]
username =input('username : ')
pin =input('password : ')
if[username,pin]in database:
print("access granted")
else:
print("retry")
网友评论