Jan-13-2017, 10:23 PM
I am testing out some basic Object Oriented Programming in Python. The basics:
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.
- 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__
- I want to use __init__
- I want to use __str__
- I want to use a while loop with a sentinel value
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.