10W -python

计算2 3 4 加运算符 小于30

>>> new=[''.join(('2',op,'3')) for op in ops]
>>> print(new)
['2+3', '2-3', '2*3', '2/3', '23']
>>> new=[''.join(('2',op,'3',op,'4')) for op in ops]
>>> print(new)
['2+3+4', '2-3-4', '2*3*4', '2/3/4', '234']
>>> new=[]
>>> for op1 in ops:
		for op2 in ops:
			new1=''.join(('2',op1,'3',op2,'4'))
			new.append(new1)
		print(new)
	len(new)

	
['234', '23+4', '23-4', '23*4', '23/4']
5
['234', '23+4', '23-4', '23*4', '23/4', '2+34', '2+3+4', '2+3-4', '2+3*4', '2+3/4']
10
['234', '23+4', '23-4', '23*4', '23/4', '2+34', '2+3+4', '2+3-4', '2+3*4', '2+3/4', '2-34', '2-3+4', '2-3-4', '2-3*4', '2-3/4']
15
['234', '23+4', '23-4', '23*4', '23/4', '2+34', '2+3+4', '2+3-4', '2+3*4', '2+3/4', '2-34', '2-3+4', '2-3-4', '2-3*4', '2-3/4', '2*34', '2*3+4', '2*3-4', '2*3*4', '2*3/4']
20
['234', '23+4', '23-4', '23*4', '23/4', '2+34', '2+3+4', '2+3-4', '2+3*4', '2+3/4', '2-34', '2-3+4', '2-3-4', '2-3*4', '2-3/4', '2*34', '2*3+4', '2*3-4', '2*3*4', '2*3/4', '2/34', '2/3+4', '2/3-4', '2/3*4', '2/3/4']

>>> new=[]
>>> for op1 in ops:
		for op2 in ops:
			new1=''.join(('2',op1,'3',op2,'4'))
			if eval(new1)<30:
				new.append(new1)

			
>>> print(new)
['23+4', '23-4', '23/4', '2+3+4', '2+3-4', '2+3*4', '2+3/4', '2-34', '2-3+4', '2-3-4', '2-3*4', '2-3/4', '2*3+4', '2*3-4', '2*3*4', '2*3/4', '2/34', '2/3+4', '2/3-4', '2/3*4', '2/3/4'] 
posted @ 2016-06-30 07:10  li_volleyball  阅读(166)  评论(0编辑  收藏  举报