Skip to content
Worked Examples · Example 4.7

Q.Algorithm for a card game called “Dragons and Wizards”.
Make two teams DRAGONS and WIZARDS
The rules for the game are as follows:
• If the card drawn is a diamond or a club, Team DRAGONS gets a point
• If the card drawn is a heart which is a number, Team WIZARDS gets a point
• If the card drawn is a heart that is not a number, Team DRAGONS gets a point
• For any other card, Team WIZARDS gets a point
• The team with highest point is the winner

Sikkim CbseNCERTSubjective· 3mImportance★★★★★est
33% · 12/36 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Translate each game rule into one branch of a chained IF: diamonds/clubs → DRAGONS, number hearts → WIZARDS, other hearts (A, J, Q, K) → DRAGONS, everything else (spades) → WIZARDS; keep two counters and compare them at the end.

The idea. This is conditional logic over two attributes of a card — its suit and whether its rank is a number (2-10) or a face/ace (A, J, Q, K). The rules are checked top-down, so each ELSE IF only sees cards not already classified. Note that "any other card" can only mean spades, since diamonds, clubs and hearts are all covered by earlier rules.

Algorithm / pseudocode:

Step 1: SET dragons = 0, wizards = 0
Step 2: REPEAT for every card drawn:
            INPUT suit, rank
            IF suit == "diamond" OR suit == "club" THEN
                dragons = dragons + 1
            ELSE IF suit == "heart" AND rank is a number (2..10) THEN
                wizards = wizards + 1
            ELSE IF suit == "heart" THEN            // heart that is A, J, Q or K
                dragons = dragons + 1
            ELSE                                    // spade
                wizards = wizards + 1
Step 3: IF dragons > wizards THEN PRINT "Team DRAGONS wins"
        ELSE IF wizards > dragons THEN PRINT "Team WIZARDS wins"
        ELSE PRINT "Match drawn"

Python implementation (with a sample set of drawn cards):

cards = [("diamond", "7"), ("heart", "K"), ("spade", "4"),
         ("heart", "9"), ("club", "A")]

dragons = wizards = 0
for suit, rank in cards:
    if suit in ("diamond", "club"):
        dragons += 1
    elif suit == "heart" and rank.isdigit():      # number card 2-10
        wizards += 1
    elif suit == "heart":                         # A, J, Q, K of hearts
        dragons += 1
    else:                                         # spade
        wizards += 1

print("DRAGONS:", dragons, " WIZARDS:", wizards)
if dragons > wizards:
    print("Team DRAGONS wins")
elif wizards > dragons:
    print("Team WIZARDS wins")
else:
    print("Match drawn")

Trace of the sample cards: …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.