gpt4 book ai didi

python - 电话号码查询程序

转载 作者:太空宇宙 更新时间:2023-11-04 08:19:40 24 4
gpt4 key购买 nike

我的数组作业有问题,我需要输入一个名称然后程序必须返回数字,但我所能做的就是返回所有这些

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()

最佳答案

使用 index 打印你想要的电话号码,而不是全部:

if found:
print 'the phone number is: ', phoneNumbers[index]

关于python - 电话号码查询程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7800944/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com