475123763
发表于 2018-6-7 16:18:47
本帖最后由 475123763 于 2018-6-7 16:19 编辑
import math
i = 0
b = []
for i in range (10):
a = int(input('请输入数字:'))
b.append(a)
print(b)
i = 0
d = []
for i in range(10):
for j in range(i,10):
c = abs(b-b)
d.append(c)
d.sort()
print(d)
print(d)
aaaqqq2004
发表于 2018-6-8 11:39:25
from itertools import permutations
nums=
print (min(abs(i-i) for i in permutations(nums,2)))
892427369
发表于 2018-7-28 12:57:09
a = input('请输入一个整数数组,以空格分开:')
b = a.split(' ')
c = []
for x in b:
if b.count(x) > 1:
print('两两之差最小的绝对值是:0')
import sys
sys.exit()
for y in b:
if not x == y:
d = abs(int(x)-int(y))
c.append(d)
print('两两之差最小的绝对值是:',min(c),sep="")
可乐必须加冰
发表于 2018-8-2 21:08:19
def func17():
list1 = list(int(i) for i in input("请输入一串数字,用空格隔开:").split(" "))
list2 = []
for j in range(len(list1) - 1):
a = abs(list1 - list1)
list2.append(a)
print(min(list2))
DavidCowboy
发表于 2018-8-7 15:10:21
a = int(input('numer01:'))
b = int(input('numer02:'))
c = int(input('numer03:'))
d = int(input('numer04:'))
e = int(input('numer05:'))
list01 = []
list02 = []
list01.extend()
for i in range(1,5):
for j in range(1,5):
if i != j:
list02.append(list01 - list01)
list02.sort()
print(list02)
quan-renda
发表于 2018-8-30 14:08:26
import random as r
n=int(input("请输入n:"))
lst=[]
lst1=[]
for i in range(n):
lst.append(r.randint(-100,100))
lst.sort()
for j in range(len(lst)-1):
s=abs(lst-lst)
lst1.append(s)
print("最小值为:",min(lst1))
Naze
发表于 2018-8-30 17:29:09
def fuk(lis):
b=[]
i = len(lis)-1
while i !=0:
x = abs(lis-lis)
b.append(x)
i = i-1
print(min(b))
回答的第一条题目,纪念一下{:10_266:}
我不会啊
发表于 2018-8-31 10:29:58
a
子沙
发表于 2018-9-2 17:17:55
def fun_17(m):
m.sort()
n=[]
for i in range(len(m)-1):
n.append(m-m)
print(min(n))
冷焰溶冰
发表于 2018-9-17 22:16:37
list =
min_list = abs(list - list)
for i in range(len(list)-1):
for j in range(i+1,len(list)):
if min_list > abs(list - list):
min = abs(list - list)
print(min)
lyslyslys
发表于 2018-9-19 17:03:33
感谢楼主
阿磕磕
发表于 2018-10-11 11:40:37
1
Nyu菌
发表于 2018-10-13 15:08:16
def zuixiao(x=):
c=len(x)
m=[]
for i in range(c):
for j in range(c):
if i==j:
continue
a=x-x
m.append(a)
n=[]
for i in m:
i=abs(i)
n.append(i)
k=min(n)
return k
print(zuixiao((1,3,7,11,6541,654165,168,1,13,21,3213,68,46)))
丨游戏灬需要
发表于 2018-10-13 19:33:49
'''有一个整数数组,请求出两两之差绝对值最小的值,
记住,只要得出最小值即可,不需要求出是哪两个数。'''
def q(temp):
temp = sorted(temp)
result = abs(temp -temp)
lenght = len(temp)
for i in range(lenght -1):
if abs(temp -temp[ i+1]) < result:
result = abs(temp -temp[ i+1])
return result
那个?不是说【有一个整数数组】么?怎么'答案'是两个数组?
double-lee
发表于 2018-12-5 12:46:37
import random as r
def nums(n_list,n):
for j in range(n):
i = r.randint(-100,100)
n_list.append(i)
return n_list
def min_abs(n_list,n_list2,n):
n_list.sort()
for i in range(n-1):
n_list2.append(abs(n_list-n_list))
returnmin(n_list2)
list1 =[]
list2 =[]
n = int(input("请输入要生成数组里数的个数: "))
print(nums(list1,n))
print(min_abs(list1,list2,n))
看了某些大神的代码,觉得自己思维还是太直了,不懂得变换和简化{:10_266:} {:10_266:}
dxyxln
发表于 2018-12-17 13:04:08
def calc(list1):
min = abs(list1 - list1)
for i in range(len(list1)):
for j in range(i+1, len(list1)):
if abs(list1 - list1) < min:
min = abs(list1 - list1)
return min
if __name__ == "__main__":
test =
print(calc(test))
咕咕鸡鸽鸽
发表于 2019-1-4 14:57:39
kankan
shencong132
发表于 2019-1-7 18:53:05
list1 =
list1.sort()
min_dif = 9999
for i in range(len(list1)-1):
if abs(list1-list1)< min_dif:
min_dif = abs(list1-list1)
print(min_dif)
北城以北灬
发表于 2019-3-4 17:25:36
arr =
print(arr)
arr.sort()
min = abs(arr - arr)
for i in range(len(arr)-1):
temp = abs(arr - arr)
if temp < min:
min = temp
print(min)
lwy520
发表于 2019-3-20 16:31:29
def zuixiaozhi(lst):
min_val=min(lst)
for i in range(1,len(lst)):
if min_val > abs(lst-lst):
min_val=abs(lst-lst)
return(min_val)
lst=
print(lst)
min_val=zuixiaozhi(lst)
print(min_val)