from random import randint
import os
path = os.path.abspath('')
dosya = open((path + "\\asaldb.txt"), "r")
asalsayilar = dosya.readlines()
mindeger = int(input("Minumum Değer Kaç ? "))
maxdeger = int(input("Maximum Değer Kaç ? "))
min=0
max=0
minasallar = []
maxasallar = []
ortakasal = []
ortakasal2 = []
def maxasal():
global max
if maxdeger>=int(asalsayilar[max]):
maxasallar.append((asalsayilar[max]).rstrip('\n'))
max=max+1
maxasal()
def minasal():
global min
if int(asalsayilar[min])>=mindeger:
try:
(asalsayilar[max]).rstrip('\n')
minasallar.append((asalsayilar[min]).rstrip('\n'))
min=min+1
minasal()
except:
print("Maximum Asallar :")"""
maxasal()
else:
min=min+1
minasal()
minasal()
def common_member(a, b):
a_set = set(a)
b_set = set(b)
if (a_set & b_set):
ortakasal.append((a_set & b_set))
else:
print("No common elements")
common_member(minasallar, maxasallar)
ortakasal.sort()
print((ortakasal[0]).rstrip('{ }'))
回溯:
^{pr2}$如果我做print (asalortak)
,它会变成这样:[{'83', '97', '53', '79', '89', '67', '61', '73', '59' }]
{do>看起来像这样:
{'83', '97', '53', '79', '89', '67', '61', '73', '59', '71'}
,但我需要分开我的号码。在
这是因为
asalortak [0]
是一个pythonset
,这个错误已经证实了这一点。在AttributeError:“set”对象没有属性“rstrip”
这些元素已经被“分开”。只需迭代元素以打印它们:
^{pr2}$在
set
中,顺序不稳定/不固定。使用sorted
从中生成排序列表(排序的alpha,不是数字,因为数字是字符串)转换为列表:
转换为排序列表:
您可以使用
random.sample(ortakasal[0],2)
随机选择2个元素。在相关问题 更多 >
编程相关推荐