您的位置:首页 > 编程语言 > Python开发

10W -python

2016-06-30 07:10 316 查看

计算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']
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: