以下是我遇到问题的部分代码:
def func():
for i in range(len(titleList)):
print titleList[i] + ' -- ' + artistList[i] + ' -- ' + albumList[i] + ' --',
print yearList[i] + ' -- ' + commentList[i]
def sequentialSearch(albumList, item):
pos = 0
found = False
while pos < len(albumList) and not found:
if albumList[pos] == item:
found = True
else:
pos = pos + 1
return found
num = input("What would you like to do?\n1. Print all the contents of the database\n2. Find all the songs on a particular album\n3. Quit\nPlease Enter 1, 2, or 3: ")
if num == 3:
print "Goodbye"
else:
while num != 3:
if num == 1:
func()
if num == 2:
item = raw_input("Please enter the album: ")
seqentialSearch(albumList, item)
else:
print "Invald Input"
我有一个数据库,这个程序正在从中提取数据。我需要它表现得像这样:
我有两个问题:
如何解决这些问题?你知道吗
类似这样的操作可以根据需要控制选项:
您的
sequentialSearch
函数没有打印任何内容。您不需要found
变量,只要在找到匹配项时从函数中return
。你知道吗在主代码中,
while
循环将永远不会结束,因为您请求循环外的num
。用途:相关问题 更多 >
编程相关推荐