1.找到1-100内的质数,用while和for来做,结束之后打印“搜索结束”.
##########1###################
zhishu=[] for i in range(2,101): for j in range(2,i): if i%j ==0: break else: zhishu.append(i) print(zhishu)
##############2#############
zhishu=[] i=100 while i>1: for j in range(2,i): if i%j==0: break else: zhishu.append(i) i-=1 print(zhishu)
2.定义一个函数,能够输入字典和元组。将字典的值(value) 和 元组的值交换,交换结束后,打印并且返回 字典和元祖。
a=[1,2,3] di={'a':11,'b':22,'c':33} def change(*args,**kwargs): args=list(args) i=0 for key in kwargs.keys(): args[i],kwargs[key]=kwargs[key],args[i] i+=1 else: print(args) print(kwargs)