6个回答

``````#!/usr/bin/env python
# -*- coding: utf-8 -*-
import random

def random_test():
# 初始化一个列表，随机0-100的6个数字
rst_list = [random.randint(0,100) for i in range(0, 6)]
print(rst_list)
while 1:
# 新建临时数据，用来存储rst_list按规则处理后的数据
temp = []
for k,v in enumerate(rst_list):
if k%2==0:
temp.append(random.randint(min([rst_list[k],rst_list[k+1]]),max([rst_list[k],rst_list[k+1]])))
else:
temp.append(random.randint(min(rst_list[k-1], rst_list[k]),max(rst_list[k-1], rst_list[k])))
# 将结果temp列表，写入结果列表 rst_list
rst_list = temp
print(rst_list)
# 判断37在结果列表中，则返回结果列表 rst_list
if 37 in rst_list:
print('rst_list:',rst_list)
return rst_list
else:
# 37没在列表中，则按要求判断死循环情况(需求里的 s1=s2!=37&s3=s4!=37&s5=s6!=37 )
# 如果进入死循环，则重新初始化结果列表 rst_list
if rst_list[0]==rst_list[1] and rst_list[2]==rst_list[3] and rst_list[4]==rst_list[5]:
rst_list = [random.randint(0, 100) for i in range(0, 6)]

def main():
random_test()

if __name__ == '__main__':
main()

``````

weixin_39017744 有相应注释，照顾了我这菜鸟。采纳你的好了，嘿嘿。
8 个月之前 回复

# 之前的代码误将调试中的代码贴出，有一行没有写正确，已经修正。

``````#!/usr/bin/python
import random

s=[0,0,0,0,0,0]
while not(37 in s):
for i in range(0,6):
s[i]=random.randint(0,100)
s.sort()
while not(37 in s): #这里之前写错了
s[0]=random.randint(s[0],s[1])
s[1]=random.randint(s[0],s[1])
s[2]=random.randint(s[2],s[3])
s[3]=random.randint(s[2],s[3])
s[4]=random.randint(s[4],s[5])
s[5]=random.randint(s[4],s[5])
if s[0] == s[1] and s[2] == s[3] and s[4] == s[5] and s[0] != 37 and s[2] != 37 and s[4] != 37:
break
print(s)
``````

``````#!/usr/bin/python
import random

s=[0,0,0,0,0,0]
while not(37 in s):
for i in range(0,6):
s[i]=random.randint(0,100)
s.sort()
while not(37 in s):
for j in range(0,6):
s[j]=random.randint(s[j//2],s[j//2+1])
if s[0] == s[1] and s[2] == s[3] and s[4] == s[5] and s[0] != 37 and s[2] != 37 and s[4] != 37:
break
print(s)
``````

8 个月之前 回复

8 个月之前 回复
weixin_39017744 这里错了吧？是要先得出第一组数然后判断第一组数中有没有37
8 个月之前 回复
``````import random

rnds=[i for i in range(6)]

def rnd():
for i in range(6):
rnds[i]=random.randint(0,100)

def rnd2(n):
low=rnds[n]
high=rnds[n+1]
if low>high:
low,high=high,low
rnds[n]=random.randint(low,high)
rnds[n+1]=random.randint(low,high)

def find(n=37):
rnd()
while 1:
flag=False;
for i in range(6):
if rnds[i]==37:
flag=True
break;
if flag:
break;
if (rnds[0]==rnds[1])&(rnds[2]==rnds[3])&(rnds[4]==rnds[5]):
rnd()
rnd2(0)
rnd2(2)
rnd2(4)
print(rnds)

find()
``````
``````    试验了，瞬间出结果
``````
soar3033 rnd2方法的形参为n，代表对s(n)及s(n+1)进行重新生成。rnd2(0)、rnd2(2)、rnd2(4)分别表示对s(0)及s(1) s(2)及s(3) s(4)及s(5) 进行重新随机生成
8 个月之前 回复
weixin_39017744 请问倒数第五行到倒数第三行，括号中的数字代表什么呀？
8 个月之前 回复
``````import random

s=[0,0,0,0,0,0]
for i in range(0,6):
s[i]=random.randint(0,100)

while not(37 in s):
for i in range(0,3):
l, r = min(s[2*i], s[2*i+1]), max(s[2*i], s[2*i+1])
s[2*i]=random.randint( l, r )
s[2*i+1]=random.randint( l, r )

while not(37 in s) and s[0] == s[1] and s[2] == s[3] and s[4] == s[5]:
for i in range(0,6):
s[i]=random.randint(0,100)

print(s)
``````
``````#coding:UTF-8
import random
s1 = None
s2 = None
s3 = None
s4 = None
s5 = None
s6 = None
result = None

def init_number():
global s1, s2, s3, s4, s5, s6, result
result = 37
s1 = random.randint(init_start, init_end)
s2 = random.randint(init_start, init_end)
s3 = random.randint(init_start, init_end)
s4 = random.randint(init_start, init_end)
s5 = random.randint(init_start, init_end)
s6 = random.randint(init_start, init_end)

def handler():
global s1, s2, s3, s4, s5, s6, result
while s1 != result and s2 != result and s3 != result and s4 != result and s5 != result and s6 != result:
if s1 < s2:
new_s1 = random.randint(s1, s2)
new_s2 = random.randint(s1, s2)
else:
new_s1 = random.randint(s2, s1)
new_s2 = random.randint(s2, s1)
if s3 < s4:
new_s3 = random.randint(s3, s4)
new_s4 = random.randint(s3, s4)
else:
new_s3 = random.randint(s4, s3)
new_s4 = random.randint(s4, s3)
if s5 < s6:
new_s5 = random.randint(s5, s6)
new_s6 = random.randint(s5, s6)
else:
new_s5 = random.randint(s6, s5)
new_s6 = random.randint(s6, s5)
s1 = new_s1
s2 = new_s2
s3 = new_s3
s4 = new_s4
s5 = new_s5
s6 = new_s6
if s1 == s2 and s1 != result and s3 == s4 and s3 != result and s5 == s6 and s5 != result:
init_number()
print s1, s2, s3, s4, s5, s6

if __name__ == '__main__':
init_start = 1
init_end = 100
init_number()
handler()
``````
``````#!/usr/bin/env python
# -*- coding: utf-8 -*-
import random

def get_37(list):

if 37 in list:
print('success_list:', list)
return list
if len(list) != 6:
list = [random.randint(0,100) for i in range(0, 6)]
print('new list:', list)
if get_2num_bweet(list,0,1,37) + get_2num_bweet(list,2,3,37) + get_2num_bweet(list,4,5,37) > 0:
print('check- contuin ',list);
return get_37(list)
else:
print('check- end - list' , list);
return 0;

def get_2num_bweet(list,i1,i2,b_num):
if(list[i1] > 37 and list[i2] < 37):
list[i1:i2+1] = [random.randint(list[i2], list[i1]) for i in range(0, 2)];
return 1
elif(list[i2] > 37 and list[i1] < 37):
list[i1:i2+1] = [random.randint(list[i1], list[i2]) for i in range(0, 2)];
return 1
else:
list[i1] = list[i2]
return 0

def main():
list = [random.randint(0, 100) for i in range(0, 6)]
while get_37(list) == 0:
list = [random.randint(0, 100) for i in range(0, 6)]
print('new list:', list)

if __name__ == '__main__':
main()

``````

python如何用循环生成并输出有规律的数组内容？

python中两个数组比较大小

python如何判断二维数组中的每一位值是否为指定数字并输出每个数组的总误差值？

python如何输入二维数组

python 字符串数组问题

for i in range(sum): res_tem1 = res_tem1.find_next('td') <-如果在循环内用字符串数组储存每次的res_tem1值？（res_tem1为字符串）

python中numpy格式数组维度

##python中numpy格式数组维度问题 ``` labels = np.empty((0,4)) xml_names = os.listdir(path) for xml_name in xml_names: image_path, label = parse_xml(os.path.join(path, xml_name)) print(label) label = np.array(label) print(label) labels = np.append(labels, label, axis=0) ``` label是这个格式： [[128 230 188 328 0] [297 199 366 299 0]] 然后和labels append的时候报错，提示维度不匹配，请问为什么

python二维数组找峰值

python创建创建数组的问题

i = 0.8 while i <2: temp= [] d = np.random.choice([3,i],size = 10, replace=True,p =[0.5,0.5]) temp.append(d) i+= 0.1 我想要把每次循环创建的数组纵向合并，为什么这个temp只有一个数组出来， 求解答！

python使用pandas两数组相加

python3 两个数组元素相乘求和，求优化

``` def sumAndMul2List(list1, list2): result = sum([a*b for a,b in zip(list1,list2)]) return result ``` 对一张图片做卷积，除了加载图片以外不能用任何库，上面这个函数跑了很长时间，请问有没有什么办法更快一点

python中如何判断一个数组中有几个不相同的数

python中如何判断一个数组中有几个不相同的数 输入 1 2 2 3 3 2 7 8 9 输出 6

MySQL数据库面试题（2020最新版）

2020阿里全球数学大赛：3万名高手、4道题、2天2夜未交卷

HashMap底层实现原理，红黑树，B+树，B树的结构原理 Spring的AOP和IOC是什么？它们常见的使用场景有哪些？Spring事务，事务的属性，传播行为，数据库隔离级别 Spring和SpringMVC，MyBatis以及SpringBoot的注解分别有哪些？SpringMVC的工作原理，SpringBoot框架的优点，MyBatis框架的优点 SpringCould组件有哪些，他们...

《Oracle Java SE编程自学与面试指南》最佳学习路线图2020年最新版（进大厂必备）

《Oracle Java SE编程自学与面试指南》最佳学习路线图（2020最新版）