{"id":17258,"date":"2021-09-30T11:00:52","date_gmt":"2021-09-30T05:30:52","guid":{"rendered":"https:\/\/python-programs.com\/?p=17258"},"modified":"2021-11-22T18:35:31","modified_gmt":"2021-11-22T13:05:31","slug":"python-program-to-print-a-deck-of-cards-in-python","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-print-a-deck-of-cards-in-python\/","title":{"rendered":"Python Program to Print a Deck of Cards in Python"},"content":{"rendered":"
In the previous article, we have discussed Python Program to Calculate Age in Days from Date of Birth<\/a> These are the cards A of Heart, K of Heart, Q of Heart, and so forth. Then there’s A of Club, K of Club, Q of Club, and so on.<\/p>\n As a result, we will have four different sets of a card, with 13 cards in each set. (Because there are 13 different values for each sign’s card)<\/p>\n As a result, the total number of cards = 13*4 = 52<\/p>\n Given two lists of cards and the task is to print a deck of cards.<\/p>\n For Loop:<\/strong><\/p>\n A for loop is used to iterate through a sequence (that is either a list, a tuple, a dictionary, a set, or a string).<\/p>\n This works more like an iterator method in other object-oriented programming languages than for the keyword in other programming languages.<\/p>\n The for loop allows us to execute a set of statements once for each item in a list, tuple, set, and so on.<\/p>\n In General:<\/strong><\/p>\n A deck of cards contains 52 cards.<\/p>\n Each card is divided into four suits, each of which contains 13 cards.<\/p>\n A deck of cards can also be classified as follows:<\/p>\n These cards are also referred to as court cards.<\/p>\n In all four suits, they are Kings, Queens, and Jacks.<\/p>\n Below are the ways to print a deck of cards.<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Explore more instances related to python concepts from\u00a0Python Programming Examples<\/a>\u00a0Guide and get promoted from beginner to professional programmer level in Python Programming Language.<\/p>\n In the previous article, we have discussed Python Program to Calculate Age in Days from Date of Birth A deck of cards contains 52 cards. There are 4 sign cards –\u00a0 ‘Heart’, ‘CLUB’, ‘DIAMOND’, ‘SPADE’ There are 13 value of cards – ‘A’,’K’,’Q’,’J’,’2′,’3′,’4′,’5′,’6′,’7′,’8′,’9′,’10’ These are the cards A of Heart, K of Heart, Q of …<\/p>\n
\nA deck of cards contains 52 cards.<\/p>\n\n
\n
Program to Print a Deck of Cards in Python<\/h2>\n
\n
Method: Using For Loop<\/h3>\n
\n
# Give the list of value cards as static input and store it in a variable.\r\ncard_values = ['A', 'K', 'Q', 'J', '2',\r\n '3', '4', '5', '6', '7', '8', '9', '10']\r\n# Give the list of signs cards as static input and store it in another variable.\r\ncrd_signs = ['Heart', 'CLUB', 'DIAMOND', 'SPADE']\r\n# Loop in the above list of value cards using the for loop and len() function.\r\nprint(\"The Deck of cards are:\")\r\nfor val in range(len(card_values)):\r\n # Inside the loop, loop again\u00a0in the above list of sign cards using the for loop\r\n # and len() function.\r\n for signval in range(len(crd_signs)):\r\n # Print the corresponding iterator values .\r\n print(card_values[val], crd_signs[signval])\r\n<\/pre>\n
A Heart\r\nA CLUB\r\nA DIAMOND\r\nA SPADE\r\nK Heart\r\nK CLUB\r\nK DIAMOND\r\nK SPADE\r\nQ Heart\r\nQ CLUB\r\nQ DIAMOND\r\nQ SPADE\r\nJ Heart\r\nJ CLUB\r\nJ DIAMOND\r\nJ SPADE\r\n2 Heart\r\n2 CLUB\r\n2 DIAMOND\r\n2 SPADE\r\n3 Heart\r\n3 CLUB\r\n3 DIAMOND\r\n3 SPADE\r\n4 Heart\r\n4 CLUB\r\n4 DIAMOND\r\n4 SPADE\r\n5 Heart\r\n5 CLUB\r\n5 DIAMOND\r\n5 SPADE\r\n6 Heart\r\n6 CLUB\r\n6 DIAMOND\r\n6 SPADE\r\n7 Heart\r\n7 CLUB\r\n7 DIAMOND\r\n7 SPADE\r\n8 Heart\r\n8 CLUB\r\n8 DIAMOND\r\n8 SPADE\r\n9 Heart\r\n9 CLUB\r\n9 DIAMOND\r\n9 SPADE\r\n10 Heart\r\n10 CLUB\r\n10 DIAMOND\r\n10 SPADE<\/pre>\n
\n