I need help trying to print my card which prints a card. Can you fix it?

Can you help fix this code?
|
|


carddict = [
    "----------------------------"
    "|  WILD                    |"
    "|                          |"
    "|                          |"
    "|      Get Errored!!       |"
    "|      ERROR!!!!!!!!       |"
    "|           =              |"
    "|          { }             |"
    "|          « «             |"
    "|          «e“             |"
    "|                          |"
    "|                          |"
    "|                          |"
    "[                    WILD  ]"
    "----------------------------"
]
def print_card(dictcard):
    for card in len(dictcard):
        print(f"\n{card}\n")
print_card(carddict)

Error:

Traceback (most recent call last):
  File "Documents/UNO® Card Game ' Get Errored WILD card.py", line 21, in <module>
    print_card(carddict)
  File "Documents/UNO® Card Game ' Get Errored WILD card.py", line 19, in print_card
    for card in len(dictcard):
TypeError: 'int' object is not 

Also i want to print 1 at a time. Can you please help?

carddict isn’t a dictionary, it’s a list containing a single str that prints all on one line. Trying to do len(dictcard) returns 1, which can’t be iterated over.

Now if you added a comma to the end of each line:

carddict = [
    "----------------------------",
    "|  WILD                    |",
    "|                          |",
...

that would give you a list where each line is a separate value, and you could just do for card in dictcard: .

1 Like

lol thanks :)

Or, better, if you’re just pre-composing the card (as opposed to, e.g., having a function to generate a card given some text) much simpler to just use a multi-line string to create the card directly:

card = """
----------------------------
|  WILD                    |
|                          |
|                          |
|      Get Errored!!       |
|      ERROR!!!!!!!!       |
|           =              |
|          { }             |
|          « «             |
|          «e“             |
|                          |
|                          |
|                          |
[                    WILD  ]
----------------------------
"""
print(card)
2 Likes

It’s alright. Currently now i have two files 1) File: “cardprinter.py”
2) File: “UNO® Card Game ’ Get Errored WILD card.py”
EDIT:

I like your idea, but i like it on a list for now. Thank you for helping me anyway!

File 1:


def print_card(lstcard):
    for card in lstcard:
        print(f"{card}")
# To demostrate how this works, we can add a card list.
if __name__ == "__main__":
    cardlst = [
        #Over here, we have a card which says "OK Error, Call 888".
        "----------------------------",
        "|  WILD                    |",
        "|                          |",
        "|                          |",
        "|   OK Error, Call 888     |",
        "|      ERROR!!!!!!!!       |",
        "|           =              |",
        "|          { }             |",
        "|          « «             |",
        "|          «e“             |",
        "|                          |",
        "|                          |",
        "|                          |",
        "[                    WILD  ]",
        "----------------------------"
    ]
    #This prints the card 1 by 1
    print_card(cardlst)
    #Now our card is done!

File 2:

import cardprinter

if __name__ == "__main__":
    cardlst = [
        "----------------------------",
        "|  WILD                    |",
        "|                          |",
        "|                          |",
        "|      Get Errored!!       |",
        "|      ERROR!!!!!!!!       |",
        "|           =              |",
        "|          { }             |",
        "|          « «             |",
        "|          «e“             |",
        "|                          |",
        "|                          |",
        "|                          |",
        "[                    WILD  ]",
        "----------------------------"
    ]
    cardprinter.print_card(cardlst)

So that is all the files!