4天时间,虽然上着班,但是学的东西还是有点多,而且晚上看的比较容易忘,所以今天是习题模式,正好教程也是这么要求的,本来以为时间不长,没想到还是很崩溃啊。不多说,上干货。
#关于随机产生验证码同时验证用户输入验证码是否正确的问题
# def check_code():
# import random
# check_code = ''
# for i in range(4):
# current = random.randrange(0,4)
# if current != i:
# temp = chr(random.randint(65,90))
# else:
# temp = random.randint(0,9)
# check_code += str(temp)
# return check_code
# code = check_code()
# print(code)
#
# test_bianma = input("请输入验证码>>>")
# test_bianma = test_bianma.lower()
# code = code.lower()
# a = 0
# while a < 4:
# if test_bianma == code:
# print("填写正确,欢迎进入")
# break
# else:
# print("验证错误请重新输入")
# a += 1
#
# # 题目练习:两个列表之间相互验算,l1 = [11,22,33,44] l2 = [22,55,44,66]
# # 获取l1中有但是l2中没有的,获取l1和l2中各自独有的元素
#
# l1 = [11,22,33,44]
# l2 = [22,55,44,66]
# new_l = []
#
# for yuansu_l1 in l1:
# # v = yuansu_l1 in l2
# if yuansu_l1 not in l2:
# new_l.append(yuansu_l1)
#
# for yuansu_l2 in l2:
# # k = yuansu_l2 in l1
# if yuansu_l2 not in l1:
# new_l.append(yuansu_l2)
#
# print(new_l)
# l1 = [1,2,3,4,5,6,7,8,8]
# count = 0
#
# for a in l1:
# for b in l1:
# if a != b:
# count += 1
# print(count)
#99乘法口诀表
# s = ""
#
# for a in range(1 , 10):
# huanhang = " "
# for b in range(a , 10):
# c = a * b
# once = "{0} * {1} = {2} "
# b = once.format(a , b , c)
# s = s + b
# s = s + huanhang
#
# s = s.expandtabs(16)
# print(s)
#100文钱买100只鸡,公鸡5文一只,母鸡3文一只,小鸡一只3文,要求每种鸡都要有,总共100只
# gong = range(1 , 100//5)
# mu = range(1 , 100//3)
# xiaoji = range(1,100)
#
# for gong_1 in gong:
# for mu_1 in mu:
# for xiaoji_1 in xiaoji:
# if (gong_1 * 5) + (mu_1 * 3) + (xiaoji_1 * 1 / 3) == 100 and gong_1 + mu_1 + xiaoji_1 == 100:
# print("公鸡有",gong_1 ," 母鸡有", mu_1 ," 小鸡有", xiaoji_1)
#请用代码实现,利用下划线将每个元素拼成字符串,li = ['alex','eric','rain']
# li = ['alex','eric','rain']
# print('_'.join(li))
#如果列表中包含数字
# s = ''
# li = ['alex','eric',123]
# for i in li:
# i = str(i)
# s = s + i
# print(s)
#有元组tu = ('alex','eric','rain')
#a.计算元组长度并输出
# tu = ('alex','eric','rain')
# print(len(tu))
#b.获取第二个元素并输出
# print(tu[1])
#c.获取元组的第1-2个元素,并输出
# print(tu[0:2])
#d.使用for输出所有元组元素
# for i in tu:
# print(i)
#e.请使用for、len、range输出元组的索引
# for i in range(0 , len(tu)):
# print(i , tu[i])
#f.使用enumrate输出元组元素和序号(序号从10开始)
#enumerate,用于对元组或列表for循环遍历,for 序号,元组元素 in enumerate(元组名,起始数字)
# tu = ('alex','eric','rain')
# for a , b in enumerate(tu , 10):
# print(a , b)
#有如下变量,请实现功能要求
# tu = ('alex',[11,22,{"k1":"v1","k2":["age","name"],"k3":(11,22,33)},44])
# #a.请讲述元组特性:
# 不能被修改、不能增加、不能删除、可以被for或者while循环遍历
#请问tu变量中第一个元素"alex"是否可以被修改?---->不可以
#请问tu变量中"k2"对应的值是什么类型?是否可以被修改,并在其中增加seven---->"k2"对应的元素为list类型,可以被修改
# tu[1][2]["k2"].append("seven") #还必须写两行,不知道为啥一行不行
# print(tu)
#请问tu变量中"k3"对应值是什么类型?是否可以被修改?----->元组,不能被修改
# bool值对应的其他值 False:() [] {} <> "" none 0
# True:对应的其他值
#找出列表 nums = [2,7,11,15,1,8,7] 当中任意两个相加可以等于9的元素集合
# nums = [2,7,11,15,1,8,7]
# for a in nums:
# for b in range(a,len(nums)):
# b = nums[b]
# once = "({0} {1})"
# if a + b == 9:
# s = once.format(a,b)
# print(s)
# #对列表 li = ['alex','eric','rain'] 做如下操作
# li = ['alex','eric','rain']
# #a.计算列表长度
# print(len(li))
#b.列表追加元素"seven",并输出
# li.append("seven")
# print(li)
#c.请在第一个位置插入元素"Tony",并输出
# li.insert(0,"Tony")
# print(li)
#d.将第二个元素修改为"Kelly",并输出
# li[1] = "Kelly"
# print(li)
#e.删除列表中元素"eric",并输出
# li.remove("eric")
# print(li)
#f.删除第2个元素,并输出
# del li[2]
# print(li)
#g.删除第3个元素,并输出所删除元素值
# v = li.pop(2)
# print(v)
#h.删除第1-2个元素,并输出所删除元素
# del li[0:2]
# print(li)
#i.将列表翻转,并输出
# li.reverse()
# print(li)
#j.使用for、len、range输出列表索引
# for i in range(0 , len(li)):
# print(i , li[i])
#k.使用enumerate输出元素和序号(从10开始)
# for a , b in enumerate(li , 10):
# print(a,b)
#l.使用for循环输出列表所有元素
# for a in li:
# print(a)
#分页显示内容
# #a.通过for循环穿件301条数据,数据类型不限
# user_list = []
# for i in range(1 , 302):
# temp = { "name" :"Alex-"+str(i) , "postbox" : "alex"+ str(i) +"@live.com" , "password" : "pwd" + str(i)}
# user_list.append(temp)
# print(user_list)
#进行分页,每页显示10条
# while True:
# s = input('请输入你想查看的页码>>>')
# s = int(s)
# start = (s - 1) * 10
# end = s * 10
# chakan = user_list[start : end]
#
# once = ''
#
# for item in chakan:
# for k , v in item.items():
# once = once + v +" "
# once = once + ' '
# new_once = once.expandtabs(30)
# print(new_once)
#
#
# q = input('是否继续查看(Y/N)>>>')
# q = q.lower()
# if q == "n":
# print('结束查看')
# break
# else:
# print('请继续查看')
最后一个题目搞得不是很熟练,后面还是要多复习啊。