Multiple prints in the same lines(cards)

import random
cartes = [2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11] * 4
joueurs = []
random.shuffle(cartes)
nb = int(input("Entrez le nombre de joueurs:"))
def carte(valeur, nombre):
    if int(nombre) < 10:
        print(" __________________")
        print("|                  |")
        print("|  {0}            {0}  |".format(nombre))
        print("|                  |")
        print("|                  |")
        print("|                  |")
        print("|        {0}         |".format(valeur))
        print("|                  |")
        print("|                  |")
        print("|                  |")
        print("| {0}             {0}  |".format(nombre))
        print("|__________________|")
    if int(nombre) > 9:
        print(" __________________")
        print("|                  |")
        print("|  {0}          {0}  |".format(nombre))
        print("|                  |")
        print("|                  |")
        print("|                  |")
        print("|        {0}        |".format(valeur))
        print("|                  |")
        print("|                  |")
        print("|                  |")
        print("| {0}           {0}  |".format(nombre))
        print("|__________________|")


def distribution():
    for i in range(nb):
        joueurs.append([])
        joueurs[i].append(cartes[i])
        joueurs[i].append(cartes[i + nb + 1])
        print("main du joueur", i + 1, ":", joueurs[i])
        carte(str(cartes[i]), str(cartes[i]))
        carte(str(cartes[i+1]), str(cartes[i+nb+1]))

distribution()

Hi, this code prints the 2 cards of each players one by one. I'm looking to put both card in the same lines so the hand of each player is seen more clearly. Do you guys have any idea how to do it ? beginner here

1 answer

  • answered 2021-05-03 18:00 MichaƂ Darowny

    Firstly I would drop explicit .format and replace with f in front of string with {} this way you can easily input stuff.

    Secondly I would craft """ """ multiple line string instead of many " " this way you could craft string with two cards next to each other.

    I can't comment so I will edit answer. Yes like you did with additional parameter

    print(<card_string>, end="")
    

    this way print won't input "\n" and next print will be next to the last one. You just have to play with it a little.