cccd
发表于 2018-3-16 20:39:21
初学者来看看大神们,学习学习
benzhj
发表于 2018-3-17 12:27:03
a =
temp = 999 #temp保存最小值.先放个足够大的数
for i in range(len(a)-1):
for j in range(i+1,len(a)):
x= a-a
if temp > abs(x):
temp = abs(x)
print(temp)
Charonnnnn
发表于 2018-3-24 16:55:36
kkkk
grf1973
发表于 2018-3-28 13:14:59
刷题练手。
Even_138
发表于 2018-3-29 10:07:04
看看
checkily
发表于 2018-3-30 00:16:17
n = int(input('输入数组的长度:'))
num_raw =
print('原始数组为:%s' % num_raw)
length = len(num_raw)
temp_list = []
for i in range(1, length):
for j in range(i, length):
temp_list.append(abs(num_raw-num_raw))
print('两两之差绝对值最小的值为:%d ' % min(temp_list))
HiaGhost
发表于 2018-3-30 10:55:02
import random
import math
def test17(n):
num = []
for i in range(n):
num.append(random.randint(1,100))
print(num)
mini = 100
for i in range(n):
for j in range(i+1,n):
temp = math.fabs(num - num)
if temp < mini:
mini = temp
if mini == 0:
break
if mini == 0:
break
print(mini)
z1446773686
发表于 2018-4-7 09:22:01
z1446773686 发表于 2018-3-9 19:12
def randlist():
list1 = []
import random
def a_b(list1,list2):
for i in list1:
for j in list1:
for x in list2:
if abs(i - j) == min(list2):
return i,j
tsembrace
发表于 2018-4-9 22:03:01
'''
有一个整数数组,请求出两两之差绝对值最小的值,
记住,只要得出最小值即可,不需要求出是哪两个数。
'''
def findsubmin(listx):
xlen=len(listx)
lista=list(sorted(listx))
listb=[]
for i in range(xlen-1):
listb.append(lista-lista)
return min(listb)
print(findsubmin())
kokawu
发表于 2018-4-10 10:26:26
楼主,你是一个大好人!!
小强工作室
发表于 2018-4-27 10:30:57
import random
import math
num=int(input("请输入需要的个数:"))
list2=[]
ra=random.sample(range(-100,100),num)#取不同重复的随机数
for i in range(len(ra)-1):
list2.append(math.fabs(ra-ra))
print(list2)
print(min(list2))
jrro452
发表于 2018-5-3 15:56:58
import random
n = 10
Nums = random.choices(,k=n)
print('一个整数数组是:')
print(Nums)
Nums = sorted(Nums)
Result = []
for i in range(len(Nums)-1):
Result.append(Nums-Nums)
print(min(Result))
jrro452
发表于 2018-5-3 15:57:33
jrro452 发表于 2018-5-3 15:56
import random
n = 10
Nums = random.choices(,k=n)
囧,忘了考虑绝对值了
jrro452
发表于 2018-5-3 16:10:02
jrro452 发表于 2018-5-3 15:57
囧,忘了考虑绝对值了
import random
n = 10
Nums = random.choices(,k=n)
print('一个整数数组是:')
print(Nums)
Nums = sorted(Nums)
Result = []
for i in range(len(Nums)-1):
Result.append(abs(Nums-Nums))
print(min(Result))
jrro452
发表于 2018-5-3 16:11:39
弱弱的想说···题主要么是出错题了,要么是代码写错了·····题目是说一组数据,题主代码求的是2组数据····
天天学习$
发表于 2018-5-4 00:06:33
def boring():
count = 0
list1 =
list_min = []
list2 = list1[:]
for i in list1:
list2.remove(i)
for j in list2:
num = i - j
list_min.append(num)
print(min(list_min))
夏未至夜未央
发表于 2018-5-4 11:15:24
data = []
while True:
x = input('请输入整数,输入其他字符结束输入:')
if x.isdigit():
data.append(int(x))
else:
break
if not data:
print('无数据!')
else:
result = []
for i in range(len(data)):
for each in data:
result.append(abs(data - each))
result = set(result)
result.remove(0)
print(min(result))
白昼
发表于 2018-5-4 13:11:03
def foo(data1,data2):
min=abs(data1-data2)
for i in data1:
for j in data2:
if abs(i-j)<min:
min=abs(i-j)
return min
a=
b=
c=foo(a,b)
print(c)
萧丹夜
发表于 2018-5-12 13:30:08
a = input('请输入一个整数数组(以空格分隔):')
b = list(map(int,a.split(' ')))
print(b)
c = []
for i in range(0,len(b)):
for j in range(i+1,len(b)):
x = b - b
if x >= 0:
c.append(x)
else :
c.append(-x)
min_a = min(c)
print(min_a)
yanchang135
发表于 2018-5-18 10:40:37
不太会