I have an unordered list, let's say:
lst = [12,23,35,54,43,29,65]
and the program will prompt the user to input two numbers, where these two numbers will represent the range.
input1 = 22
input2 = 55
therefore, 22 will be the lowest range and 55 will be the largest range. then with these two range, i want to print the values in the list within these range which are:
23
29
35
43
54
Here's my code:
def valRange(input1,input2,l):
n = len(l)
i = 0
upper = input2
lower = input1
while i<n:
if (lower<=l[i]<=upper):
l = l[i]
i+=1
return l
print(valRange(input1,input2,lst))
I'm getting an error saying int object is not subscriptable. Am I comparing it right?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…