【发布时间】:2014-12-27 05:20:16
【问题描述】:
这是我遇到问题的一些代码的一部分:
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"
我有一个数据库,该程序从中提取数据。我需要它表现得像这样:
- 如果输入 1,程序将返回数据库的全部内容
- 如果输入 2,我希望程序使用顺序搜索来打印有关该专辑中歌曲的所有信息
- 如果输入 3,我只想打印“再见”
我遇到的两个问题是:
- 我的顺序搜索代码未返回正确的信息
- 我希望程序循环直到输入 3。
我该如何解决这些问题?
【问题讨论】: