2022-10-20 21:22:14 +00:00
|
|
|
# Convert a telephone number into corresponding name, if on list.
|
|
|
|
# (If not on list, just return the number itself.)
|
|
|
|
|
|
|
|
|
|
|
|
def telToName(tel, telList, nameList):
|
|
|
|
# your code here
|
2023-01-30 16:48:43 +00:00
|
|
|
for index, t in enumerate(telList):
|
2022-10-31 20:25:31 +00:00
|
|
|
if t == tel:
|
2023-01-30 16:48:43 +00:00
|
|
|
return nameList[index]
|
|
|
|
return tel
|
2022-10-20 21:22:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Return list of telephone numbers corresponding to names containing partName.
|
|
|
|
def nameToTels(partName, telList, nameList):
|
|
|
|
# your code here
|
|
|
|
tels = []
|
2023-01-30 16:48:43 +00:00
|
|
|
for index, name in enumerate(nameList):
|
2022-10-31 20:25:31 +00:00
|
|
|
if partName in name:
|
2022-10-20 21:22:14 +00:00
|
|
|
tels.append(telList[index])
|
|
|
|
return tels
|
|
|
|
|
|
|
|
def main():
|
|
|
|
# Lists of telephone numbers and names
|
|
|
|
telList = ['975318642', '234000111', '777888333', '911911911']
|
2023-05-16 20:14:36 +00:00
|
|
|
nameList = ['Angelina', 'Brad', 'Claudia', 'Bruna']
|
2022-10-20 21:22:14 +00:00
|
|
|
|
|
|
|
# Test telToName:
|
|
|
|
tel = input("Tel number? ")
|
2023-05-16 20:14:36 +00:00
|
|
|
print( telToName(tel, telList, nameList) )
|
|
|
|
print( telToName('234000111', telList, nameList) == "Brad" )
|
|
|
|
print( telToName('222333444', telList, nameList) == "222333444" )
|
2022-10-20 21:22:14 +00:00
|
|
|
|
|
|
|
# Test nameToTels:
|
|
|
|
name = input("Name? ")
|
2023-05-16 20:14:36 +00:00
|
|
|
print( nameToTels(name, telList, nameList) )
|
|
|
|
print( nameToTels('Clau', telList, nameList) == ['777888333'] )
|
|
|
|
print( nameToTels('Br', telList, nameList) == ['234000111', '911911911'] )
|
2022-10-20 21:22:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|