2 2 2 = 6
3 3 3 = 6
4 4 4 = 6
5 5 5 = 6
6 6 6 = 6
7 7 7 = 6
请给上列各个等式加上合适的算术或数学符号,只能加符号不能加数字。
Python
#!/usr/bin/env python
#encoding:utf-8
'''Risk2S'''
import math
list = ['+','-','*','/']
print "sign:",list
for i in xrange(2,10):
for y in list:
for x in list:
b = ("(%d)%s(%d)%s(%d)"%(i,x,i,y,i))
if eval(b)==6:
print (b+'='+'6').replace('(','').replace(')','')
多重循环。