1.有两个列表 l1 = [11,22,33]
l2 = [22,33,44] 获取内容相同的元素列表
l1 = [11,22,33]
l2 = [22,33,44]
for i in l1:
for t in l2:
if t == i:
print(t)
else:
pass
(也可以用 if语句 if i in l1...)
2.有1、2、3、4、5、6、7、8 8个数字,能组成多少个互相不同而且无重复数字的两位数,并输出这些数字
count=0
li=[]
for i in range(1,9):
for t in range(1,9):
c1 = str(i)
c2 = str(t)
if c1 != c2:
c = c1+c2
if c not in li:
li.append(c)
count+=1
else:
pass
print(li)
print(count)
3.输出乘法表
for i in range(1,10):
string=''
for j in range(i,10):
string+=str(i)+'*'+str(j)+'='+str(i*j)+' '
print(string)
4.用python开发程序自动计算方案
公鸡5文钱一只,母鸡3文钱一只,小鸡3只一文钱,用100文钱买100只鸡,其中公鸡、母鸡、小鸡都必须要有,问公鸡、母鸡、小鸡分别多少只刚好凑足100文钱?
for x in range(1,100//5):
for y in range(1,100//3):
for z in range(1,100):
if x+y+z == 100 and 5*x+3*y+z/3 ==100:
print(x,y,z)
5.有以下列表 nums = [2,7,11,15,1,8,7]
请找到列表中两个元素相加能够等于9的元素集合
nums = [2,7,11,15,1,8,7]
for i in range(0,len(nums)):
for j in range(0,len(nums)):
if nums[i] + nums[j] == 9:
print(nums[i],nums[j])