0

How can I fix the "input ==1:" on line 19 problem such that if i input "1" it must have an output of

A-C,2-C,3-C,4-C,5-C,6-C,7-C,8-C,9-C,10-C,J-C,Q-C,K-C

This is my trial and error code for this problem

from typing import List, Any
import random

def printmenu():
    print("Menu")
    print("1. Show first 13 cards")
    print("2. Shuffle and show first 13 cards")
    print("3. Play 2 card poker")
    print("4. Stack the deck and show first 13 cards")
    print("5. Exit")
    _input: int = int(input())
    return options(_input)


def options(_input: int):
    suits = ['C', 'D', 'H', 'S']
    value = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']
    deck = []
    if _input == 1:
        first13cards = []
        if(deck == []):
            for i in suits:
                for j in value:
                  print(j+"-"+i, end=",")
        elif deck != []:
            deck.clear()
            first13cards.clear()
            for i in range(52):
                deck.append(value[random.randint(0, 12)] + suits[random.randint(0, 3)])
            for i in range(13):
                first13cards.append(deck[i])
        return printmenu()
    elif _input == 2:
        for i in range(13):
            deck.append(value[random.randint(0, 12)] + suits[random.randint(0, 3)])
        print(deck)
        return printmenu()
    elif _input == 3:
        #play 2 cards poker
        return printmenu()
    elif _input == 4:
        #stack the deck & show first13 cards
        return printmenu()
    elif _input == 5:
        exit()  # exit the program
    
    for j in value:
        suit = suits[random.randint(0, 3)]
        _temp = j + suit + ""
        deck.append(_temp)
    print(deck)
    return deck


if __name__ == '__main__':
    while True:
        printmenu()
        if printmenu() == 5:
            break

This is my trial and error code for this set

1 Answers1

0

For the string value that you're looking for, you could do something like

deck = ",".join(map(lambda x: x + '-C', value))

where each suit will be concatenated with -C, then joined together into one string with each element separated by a comma.

Ryan Cahill
  • 662
  • 3
  • 10