我有我的数组作业问题,我需要输入一个名字,那么程序必须返回数字,但我可以把它做的是恢复所有的人都电话号码查找程序
def main():
people = ['todd','david','angela','steve','bob','josh','ben']
phoneNumbers = ['234-7654','567-1234','888-8745','789-5489','009-7566','444-6990','911-9111']
found = False
index = 0
searchValue = raw_input('Enter a name to search for phone number: ')
while found == False and index < len(people):
if people[index] == searchValue:
found = True
else:
index = index + 1
if found:
print 'the phone number is: ',phoneNumbers
else:
print 'that name was not found'
main()
你必须使用数组吗?字典在这里是一个更好的数据类型... – tobyodavies