思路:
1、共4个数字,把第一个数字取值(0,4),后面3个取值(-4,4)来解决加减随机的问题
2、生成4个数字
3、把4个数字相加,把和等于4的存储起来
4、打印出满足条件的集合
#python3
import random
import time
randomList = []
def main():
num1 = random.randint(0,4)
num2 = random.randint(-4,4)
num3 = random.randint(-4,4)
num4 = random.randint(-4,4)
if num1+num2+num3+num4 == 4:
a = num1,num2,num3,num4
randomList.append(a)
print(randomList)
def do_while():
while True:
main()
time.sleep(0.01)
do_while()
while True:
a = random.randint(0, 4)
b = random.randint(0, 4)
c = random.randint(0, 4)
d = random.randint(0, 4)
if a + b + c + d == 4:
print a, b, c, d
break
if ......: # 后面7种运算情况
pass