Код: Выделить всё
def my_func(x):
if x > 5:
print(x)
else:
quit()
print('this should be printed only if x > 5')
Код: Выделить всё
for i in [2, 3, 4, 5, 6, 7]:
my_func(i)
Код: Выделить всё
6
this should be printed only if x > 5
7
this should be printed only if x > 5
Я знаю, что следующая функция будет работать, но я не хочу иметь вторую распечатайте там:
Код: Выделить всё
def my_func(x):
if x > 5:
print(x)
print('this should be printed only if x > 5')
else:
pass
Итак, что нужно изменить в первой функции, чтобы добиться ожидаемого результата?
Подробнее здесь: https://stackoverflow.com/questions/786 ... -in-a-loop