我有我的數組作業問題,我需要輸入一個名字,那麼程序必須返回數字,但我可以把它做的是恢復所有的人都電話號碼查找程序
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