Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!

Patrick De

Ranch Hand
+ Follow
since Apr 26, 2015
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Patrick De

Here is my question : is it possible using inheritance, to have a parent class with a DEFAULT argument that would automatically be assigned to an object (whether it is a child or parent class object) BUT if an object (using the child class), wants to over-write that attribute, it can do that as well??  The child would be using super and inheritance.  Just some sample code below to show what I  mean.

WORKS : As soon as I create an object, such as a= F1(), since there is already a default argument, it assigns the object as  sick="flu".  If I create another object b=F1("mumps"), it will be over-written.

DOESN'T WORK (yet) : If I create a child class c=F2("bed rest"), I want to take the default of sick="flu" from the parent since it is inheriting that.  Right now, it tells me it is missing an argument  

WORKS: If I want to over-write the parent argument of "sick" with an object using the Child class d= F2("measles","doctor"), it will also do this.

Hopefully that makes sense.  Thanks in advance.
2 years ago
I know that I can get one text entry box with GUI using  : msg = turtle.textinput("your login", "What is your login")

But I was wondering if there is a way to create multiple text entry boxes in the same window?
2 years ago
I was informed I should use

I can see it works, but I was hoping there was another way
3 years ago
Ok, I tried this :

3 years ago
I was going to create a  list of all of the functions and pick randomly through the list, but that doesn't work because the function names are local,
3 years ago
Thanks for trying, but yes I need it in python.
3 years ago
Is there a way to call a random method (out of a set of methods) in a class purposefully?
3 years ago
I will post the code when I get it closer to being somewhat correct.  I find for myself, working this way is more productive, I hope people don't mind.  I have put more descriptive pseudo-code below :
Ok, I changed the sentinel value and I am not going to be using that anymore.  Instead I am going to ask the user if they want to keep adding to the database, if no, then break, if yes, then continue.  

Another problem!  

can't assign to a function call

count= 0

class car
initialize all of the values and put self so they are available to the entire class
def __init__(self, model...)
 self.model=model etc
 self.serial = serial

while loop
input model =what is the model
input serial = what is the serial
input doors = how many doors
count = count + 1
#create the instance/object
mycar (count) = car(model, serial, doors)

input do you want another car in the database?
if yes
if no

The issue is that when creating an object/instance, python won't let me use this syntax of having -- mycar(count) which would give me multiple objects (mycar1, mycar2, mycar3 etc) with the count variable.  I am not sure why.
3 years ago
I was thinking about something like this :

While quit is not entered
enter your name (quit to exit)
enter your age (quit to exit)
enter your id (quit to exit)

All of this information gets passed into the class via __ini__
The initial entering of information isn't in a class
3 years ago
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

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.
3 years ago
Ok I got part of it working on my own, now I can take out books from the series (Denny) and take out individual books (Bill).  But I am stuck on Denny taking individual and a series at the same time.

3 years ago
I am trying to use Classes to instantiate an object.  I am entering in the name of a book and the number of books in the series.  I want to take that info and append it to a list.  Any ideas?
For example :

title - # books
Maze Runner, 3

I want to use the range of 3 to have it add the books to a list - such as
maze runner #1
maze runner #2
maze runner #3

I thought I had it correct using the __str__ but I have gone wrong somewhere (probably many places).

3 years ago
Yes I see what you mean.  Only in recursion does it not recreate a fresh copy, right?
Can you explain what scope is please?
3 years ago
I am work on a function that, depending on what the user inputs, will continually update and total.
For example, the user inputs the number 6, and then the user inputs the number 3 and lastly inputs the number 2 - I want it to go through the function for each individual input and add to the running total.  Something similar to this.  Do I need to put the numbers in a list as they are inputted instead?

3 years ago
And if it only returns "1", then the answer should be "1", not 120.
4 years ago