Click here to Skip to main content
15,905,238 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Actually I did not understand a question of a problem. I am using Python 3.7 and trying to use class to solve my problem. My problem is asking to use one method inside a class which will represent number between range 1-13 and which will indicate the ranks Ace through King. Another method is single character"c","d","h" or "s".. The __init__ method will initialize a single new Card object after storing the number for its first method (rank), and storing the character for its second method (suit) in instance variables.
I will appreciate if someone explains the problem.

What I have tried:

I did not understand the question and so could not try.
Updated 9-Feb-19 23:25pm

This is fundamental to how classes (and OOPs generally) works, so it's important you understand this well. I'd strongly suggest you go back over the last couple of lectures and their notes (and chapters in any course book you are reading) because you seem to have missed all the important stuff.

A class is a container that holds all the information about an object instance, together with operations that can be done with that type of object.
For example, a Car object will have a "colour", a "number of wheels", an "Engine type", an "engine size", a "VIN", a "registration number", and functions like "Unlock", "Lock", "Set Alarm", "Drive", "Accelerate", "Steer", "Brake", and so on.

Your Card class needs to store all the information to uniquely identify that card in the deck: "3 of hearts", "Ace of clubs", and so on. So create a new class, add the rank - 1 for Ace, 13 for King - and Suite - 'c' for Clubs, 'h' for Hearts - and write a __init__ method that accepts those values and stores them.
You can then add a function that returns a string based on the Rank and Suite: "3 of Hearts", "Ace of Clubs", ...

If your notes don;t make any sense, then start here: 9. Classes — Python 3.7.2 documentation[^] and read it carefully - it's really important that you understand this, not just copy code from someone else!
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900