How to return to previous code in python
I'm pretty new to programming, but I've got a quick question. I'm trying to write a sort of "choose your own adventure" game, but I've run into a problem. I'm only really as far into Show
For example:
In the
mkrieger1 15.6k4 gold badges45 silver badges57 bronze badges asked Sep 25, 2014 at 17:51
5 Are you looking for a I think that this website explains it very well: http://www.tutorialspoint.com/python/python_while_loop.htm
→
answered Sep 25, 2014 at 17:55
kaykay 24.7k10 gold badges96 silver badges139 bronze badges Use a
You need to use To
break the loop you could add a print outside the loop Then in your code add:
answered Sep 25, 2014 at 18:00
2 Not the answer you're looking for? Browse other questions tagged python loops or ask your own question.
Using breakThe
Using continue
break and continue visualizedWhat happens when we run the code from this Python file?
ResultsSee if you can guess the results before expanding this section. Using break and continue in nested loops.Remember,
Loop Control in while loopsYou can also use
Be careful that your condition will eventually be met, or else your program will get stuck in an infinite loop. For production use, it’s better to use asynchronous programming. Loops and the return statementJust like in functions, consider the
How do I go back to previous step in Python?How to return to previous part of the program (Python). ask for a string.. check if all letter in a predefined list.. if any letter is not in the list then ask for a new string, otherwise go to next step.. ask for a second string.. check again whether the second string's letters in the list.. How do you go back to the first line in Python?To read the first line of a file in Python, use the file. readline() function. The readline() is a built-in function that returns one line from the file. Open a file using open(filename, mode) as a file with mode “r” and call readline() function on that file object to get the first line of the file.
|