#๐ Need help in restructuring my code to OOP
74 messages ยท Page 1 of 1 (latest)
@wet venture
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
looks like you at the very least need a Card class.
Can you describe what attributes a Card has?
Like there are total of 52 cards
There are 4 types of cards: Spade,club,diamond,heart
Each type got a king,queen, jack,ace and numbered cards from 2-10
These two things are called the suit (space, club, etc.) and the rank (2-10 K Q J A)
so instances of your card class will have those two attributes
do you know how to define a class that has those two attributes?
if you don't know, I can help write it
Like def __init__(self,one,two)
Yeah
that's part of it. try writing the whole thing
fixed
Ok
(don't worry about what "public" means for now. or "private".)
fair
just to ensure no complexity i sent that
if you don't how how to do code blocks, just type py
!code
it's like this ^
(this doesn't really exist as a language concept in python, but only as a naming convention)
let's drop this discussion, so we don't confuse OP
i know
class Cards():
def __init__(self,suit,rank):
self.suit = suit
self.rank = rank```
Like this right?
Ahh okk
That looks great!
Remember that the class represents one card. Not a group of cards. so calling it Cards instead of Card is confusing.
you'll create multiple instances of the Card class, though.
It looks to me like the only method you need is value, to do the work of calculating and returning the card's value.
Can you try writing that method?
Here is an example:
class Foo:
def __init__(self):
self.ex = 5
def do_something(self):
pass
foo = Foo()
foo.do_something()
Yeah i have done that
the code he sent has functions in it, of course he has
I mean yeah this I know how to do it but as stelercus said the value method will calculate
I'm not able to figure out what will it calculate
that is a logic thing, not a syntax thing we can help much on
i don't know how cards work anyway
I still don't get that how will we even use class to store the cards without making a list of tuples
cards are just hard surface you use to imprint something o_O?
your class should have the necessary parameters
so a simple list would do
List of tuples is fine, what wrong with it?
looking at the original code, it could cleanly become
cards = [Card("A", "Spades"), Card(1, "Spades"), ...]
This is interesting
Let me try to write the code of this
@sleek skiff
scroll up
k
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.