K
K
korjik2283372021-07-15 19:05:41
Python
korjik228337, 2021-07-15 19:05:41

I am writing an address book. The function below should change the address and then terminate the while loop. But why doesn't the break statement work?

def change():
    while True:
        ch = input('\tВведите имя контакта чей адресс вы хотите изменить:\n')
        if ch == '':
            print('вы ничего не ввели')

        for c, v in ab.items():
            if c == ch:
                new_address = input('Введите новый адресс:\n')
                ab[c] = new_address
                print('Адресс успешно изменен')
                break

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wispik, 2021-07-15
@korjik228337

Because break breaks the first loop it's in, which is for. In this case, get a boolean variable and execute while for example when it is true, and together with break change its value to false

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question