'Controlling program flow, functions etc

Go easy on me, I'm a newb with Python. I am taking a python class. My programming experience is mostly from years ago, with different versions of BASIC, more recently, some ladder logic etc. I understand logic in the digital sense.

Let's say I am having a user enter several strings. After some evaluation, the program finds that some of the strings were not what was requested. At that point, I want to display an error message and then "try again", and then have the program go back to the lines that ask for the input. (Don't get hung up on this scenario, its just basic flow in general I want to understand better.

It seems to me to be the simplest of tasks. A goto. A gosub/return. calling a module in my ancient Quattro Pro macros. It would be nice to have sections of code that can be accessed from different points in the program flow, and then go BACK to where it branched from.

Ive read a bit about "functions"...they seem at first glance to be the answer..define a funtion, then call it later. How do you then get back to where you were? And what are the arguments in a def_function() for? I simply want a tag, a marker so that I can say go here and run until I say come back. can a funtion without arguments be used like this? if so, how do you get the flow to come back to where you told it to access that function?

Someone made a goto for python Ive read, but it's frowned upon etc,etc...hard to trace and debug, i get that, but defining a tagged set of code, accessing it by calling that tag, then returning to the line after it had been called is quite easy to track down, and one of the most basic functions of the programming I have done. Am I wrong that Python seems to have made this...difficult?

Thanks in advance! Neil



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source