"End" inside a loop | Sololearn: Learn to code for FREE!

+1

"End" inside a loop

When using an "end" inside a loop to end a program, it works properly for Code Coach challenges, but it displays an error message if I try to do the same on Jupyter Notebooks. Why? Is there a better option than using the "end" inside a loop to achieve the expected result? Here is an example: string = input() chars_set = set() for char in string: if char in chars_set: print('Deja Vu') end else: chars_set.add(char) print('Unique')

5/6/2020 11:32:19 AM

Isabela Poley

10 Answers

New Answer

+6

If you want to end the whole program you can import sys. Then you can use sys.exit() at the desired location. The program will then end properly.

+5

end is a keyword to the print function only not for python in general. print("Deja vu" , end="")

+4

end is not a Python keyword. Do you mean 'break'?

+3

As HonFu mentions end is not a valid Python keyword, I think you are confusing it with other syntax for other language. "break" is the Python substitute for end

+3

"Break" would only end the loop, not the program.

+3

It worked! Thank you, Crash!

+3

Isabela Poley My pleasure!

+2

Olá, Matheus Stefani. Esses dois cursos são visíveis apenas no aplicativo para smartphone. Não aparecem no site do SoloLearn.

+1

Muito obrigado!! Isabela Poley

0

Hi Isabela, it does not belong to this topic but I saw you mentioned some courses here, but I cannot find it. Please, where I can find it? "The new SoloLearn courses on "Data Science with Python" and "Machine Learning" are a great way to start!" Thanks