我的代码:
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
def minasal():
global min
if int(asalsayilar[min])>=mindeger:
print("Min : ")
print(asalsayilar[min])
min=min+1
minasal()
if not int(asalsayilar[min])>=mindeger :
min=min+1
minasal()
minasal()
def maxasal():
global max
if maxdeger>=int(asalsayilar[max]):
print("Max : ")
print(asalsayilar[max])
max=max+1
maxasal()
maxasal()
TreeBack:
Traceback (most recent call last):
File "asal.py", line 25, in <module>
minasal()
File "asal.py", line 21, in minasal
minasal()
File "asal.py", line 21, in minasal
minasal()
File "asal.py", line 21, in minasal
minasal()
[Previous line repeated 21 more times]
File "asal.py", line 18, in minasal
minasal()
File "asal.py", line 18, in minasal
minasal()
File "asal.py", line 18, in minasal
minasal()
[Previous line repeated 66 more times]
File "asal.py", line 14, in minasal
if int(asalsayilar[min])>=mindeger:
IndexError: list index out of range
如果我只运行maxasal()或只是minasal yi work。但他们不能一起工作。 如何创建包含两个元素和一个公共元素的列表? (maxasal()和minasal()) 为什么我会收到此错误,如何解决?