Hi, I'm going to document my code, here is my code:
card.py
import random
class Card:
"""
The Card class represents a single playing card and is initialised by passing a suit and number.
"""
def __init__(self, suit, number):
self._suit = suit
self._number = number
def __repr__(self):
return self._number + " of " + self._suit
@property
def suit(self):
""" Gets or sets the suit of the Card """
return self._suit
@suit.setter
def suit(self, suit):
# there is no need for a docstring on a setter
if suit in ["hearts", "clubs", "diamonds", "spades"]:
self._suit = suit
else:
print("That's not a suit!")
@property
def number(self):
return self._number
@number.setter
def number(self, number):
valid = [str(n) for n in range(2,11)] + ["J", "Q", "K", "A"]
if number in valid:
self._number = number
else:
print("That's not a valid number")
class Deck:
"""
The Card class represents a single playing card and is initialised by passing a suit and number.
"""
def __init__(self):
self._cards = []
self.populate()
def populate(self):
suits = ["hearts", "clubs", "diamonds", "spades"]
numbers = [str(n) for n in range(2,11)] + ["J", "Q", "K", "A"]
self._cards = [ Card(s, n) for s in suits for n in numbers ]
def shuffle(self):
random.shuffle(self._cards)
def deal(self, no_of_cards):
dealt_cards = []
for i in range(no_of_cards):
dealt_card = self._cards.pop(0)
dealt_cards.append(dealt_card)
return dealt_cards
def __repr__(self):
cards_in_deck = len(self._cards)
return "Deck of " + str(cards_in_deck) + " cards"
deck = Deck()
print(deck)
.. card documentation master file, created by
sphinx-quickstart on Sat May 29 10:49:28 2021.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to card's documentation!
================================
.. toctree::
:maxdepth: 2
:caption: Contents:
code
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
Hi, I'm going to document my code, here is my code: card.py
code.rst
index.rst
index.html
So when i run the code, it's work perfectly, withwhen i click on the "code docs", so it's not shows any code
Environment info