+ 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')

6th May 2020, 11:32 AM
Isabela Poley
Isabela Poley - avatar
9 Answers
+ 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.
6th May 2020, 12:31 PM
Crash
Crash - avatar
+ 4
end is not a Python keyword. Do you mean 'break'?
6th May 2020, 11:33 AM
HonFu
HonFu - avatar
+ 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
6th May 2020, 11:36 AM
Akash
Akash - avatar
+ 3
"Break" would only end the loop, not the program.
6th May 2020, 11:42 AM
Isabela Poley
Isabela Poley - avatar
+ 3
It worked! Thank you, Crash!
6th May 2020, 12:35 PM
Isabela Poley
Isabela Poley - avatar
+ 3
Isabela Poley My pleasure!
6th May 2020, 12:37 PM
Crash
Crash - avatar
+ 2
OlĂĄ, Matheus Stefani. Esses dois cursos sĂŁo visĂ­veis apenas no aplicativo para smartphone. NĂŁo aparecem no site do SoloLearn.
18th May 2020, 8:40 PM
Isabela Poley
Isabela Poley - avatar
+ 1
Muito obrigado!! Isabela Poley
19th May 2020, 10:00 AM
Matheus Stefani
Matheus Stefani - avatar
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
18th May 2020, 8:00 PM
Matheus Stefani
Matheus Stefani - avatar