I found out that this is what I am struggling the most. I know how to write a function:
def test(a,b):
for x in range(20):
if x == 15:
return
print("test")
test()
but I don't know how to create a function with something already written:
contacts = {"Alice": "+1554", "Bob": "+1885", "Carol": "+1006", "Felix":"+1604", "Max":"+1369","Chris":"+1882","Lea":"+1518","Linn":"+1742","Julia":"+1707"}
def phone_book(name,book):
if name in contacts:
return book
while True:
print('Enter a name: (blank to quit)')
name = input()
if name == '':
break
if name in contacts:
print(contacts[name] + ' is the number of ' + name)
I cannot bring to this code to work if I try to utilize a function. Can you explain me how to do this? You don't need to write the code. I really want to understand it.