How can I make a sentinel value NOT be initialized in a class/method - OOP?

sohcahtoa82 at gmail.com sohcahtoa82 at gmail.com
Fri Jan 13 20:02:30 EST 2017


On Friday, January 13, 2017 at 2:27:04 PM UTC-8, David D wrote:
> I am testing out some basic Object Oriented Programming in Python.  The basics: 
> 
> -User enters a name 
> -While loop with a sentinel value of "quit" will continue entering names until the sentinel value is reached 
> -The object is created with the inputted value (NAME and until a sentinel value is entered) 
> -the object is then printed out using the constructor __str__ 
> 
> In my solution ( I am saying this because someone might have a work around that doesn't include the following below) 
> -I want to use __init__ 
> -I want to use __str__ 
> -I want to use a while loop with a sentinel value 
> 
> EXPLANATION: 
> I want to have the user enter in their NAME using a while loop, with "quit" being the sentinel value that breaks the loop.  Once the name is entered, an object is created and it is passed into a constructor def __ini__ (self, name) and then I have them return a string value using __str__ for the name entered. 
> The issue I am having is that when i enter the sentinel value of QUIT, it gets initialized as the name and printed out.  How can I get around this?  I hope this makes sense.

It would help if you posted your code to see what you're doing.

Also, is the sentinel value supposed to be "quit" or "QUIT"?  If you're only checking for "quit", but you type "QUIT", it isn't going to work.  Programs execute exactly as you write them, and "quit" is not the same as "QUIT".



More information about the Python-list mailing list