【发布时间】:2019-03-29 08:16:54
【问题描述】:
try:
target = int(input("Please enter the ammount you are looking for :"))
except ValueError:
print("wrong value please enter a number")
target = int(input("Please enter the ammount you are looking for :"))
found = False
location = [] # I want to use this list as position argument for another array passed from another function. is it possible?
for pos in range(0, len(wydatki)):
if wydatki[pos] == target:
found=True
location.append(pos)
if found==True:
#prints the locations in the list that the target was found
print (target,"\nappears in the following locations: ",months[location])
else:
print (target,"\nwas not found in the list.")
months[location]
通常你只能使用单个变量来指向数组中的位置?
【问题讨论】:
-
我无法理解您的问题。您希望能够使用列表中的索引打印数组中项目的位置吗?就像如果你有一个列表
a = ['apple', 'banana', 'carrot']和另一个索引列表b = [0, 2],你会得到apple, carrot?
标签: python arrays list arguments python-3.7