Skip to main content

All the code until now (cards 4)



I will post the code until now and the output

cards = [str(num)+color for num in range(1,11) for color in ['♥','♦','♣','♠']]
x = 0
for c in cards:
    print(c,end=' ')
    x +=1
    if x==10:
        x = 0
        print()


from random import shuffle
shuffle(cards)

def pop(cardnum):
    'pc1 = pop(3) # it gives a list of 3 cards as result'
    cardlist = []
    for i in range(cardnum):
        cardlist += [cards.pop()]
    return cardlist
pc1 = []
pc1 = pop(3)
print("Pc1 cards: ", pc1)

briscola = pop(1)
print("Briscola", briscola)

def choose(cards):
    'It chooses among cards, little cards first, then little briscole, then big cards'
    cardschoice = []
    for c in cards:
        card_color = c[-1]
        briscola_color = briscola[0][-1]
        match = card_color == briscola_color
        if not match:
            cardschoice += [c]
    number = len(cardschoice)
    return cardschoice

def smallest(cards):
    card = min(cards)

def choose2(cards):
    cartascelta = ''
    leng = len(cards)
    if leng == 1:
        cartascelta = cards[0]
    if leng == 2:
        cartascelta = smallest(cards)
        

def evaluate(cards):
    dict_card = {}
    for c in cards:
        num= int(c[:-1])
        val = {x:0 for x in range(1,11)}
        val[1]=11
        val[3]=10
        val[8]=2
        val[9]=3
        val[10]=4
        dict_card[c] = val[num]
    return dict_card


cardsvalues = evaluate(cards)
print("Cards values:",cardsvalues)


cardsToChoose = choose(pc1)
print("Choose among: ",cardsToChoose)

print("Pc cards values:",evaluate(pc1))
1♥ 1♦ 1♣ 1♠ 2♥ 2♦ 2♣ 2♠ 3♥ 3♦ 
3♣ 3♠ 4♥ 4♦ 4♣ 4♠ 5♥ 5♦ 5♣ 5♠ 
6♥ 6♦ 6♣ 6♠ 7♥ 7♦ 7♣ 7♠ 8♥ 8♦ 
8♣ 8♠ 9♥ 9♦ 9♣ 9♠ 10♥ 10♦ 10♣ 10♠ 
Pc1 cards:  ['4♣', '8♠', '5♣']
Briscola ['7♠']
Cards values: {'7♦': 0, '5♠': 0, '4♠': 0, '9♥': 3, '10♣': 4, '5♥': 0, '6♦': 0, '5♦': 0, '9♦': 3, '2♦': 0, '1♥': 11, '1♠': 11, '6♠': 0, '10♦': 4, '9♣': 3, '3♥': 10, '1♦': 11, '3♦': 10, '8♣': 2, '10♥': 4, '4♥': 0, '3♣': 10, '8♦': 2, '1♣': 11, '8♥': 2, '2♥': 0, '6♥': 0, '3♠': 10, '2♣': 0, '10♠': 4, '6♣': 0, '9♠': 3, '2♠': 0, '4♦': 0, '7♣': 0, '7♥': 0}
Choose among:  ['4♣', '5♣']
Pc cards values: {'5♣': 0, '8♠': 2, '4♣': 0}


Comments

Popular posts from this blog

Widgets for Jupyter Notebook: a text input widget

Widgets for Jupyter notebook ¶ Let's import the module ipywidgets into the Jupyter Notebook from ipywidgets import widgets from ipywidgets import * from traitlets import * Now we import the display function from IPython ¶ let's attach a function to the event on_submit After we run this cell, we can go up and write something in the text widget and after you submit the text you wrote will be printed after the cell from IPython.display import display text = widgets . Text () display ( text ) def handle_submit ( sender ): print ( "Thank you for entering this text:" , text . value ) text . on_submit ( handle_submit ) Thank you for entering this text: Ciao

Image in Jupyter and PIL step by step

Hi, """ Hi, we will see a step by step tutorial about PIL and IPython.core.display modules to create images from other images and diplaying them in Jupyter notebook """ # What we will do # Create a card # 1. Take a pic of a heart # 2. Create an image blanck the size of a card 90*130 # 3. Paste the heart in the middle # 4. show the card """ As first step wi will simply display an image on the notebook. I will show two way to display the image with 'display' from IPhyton a. Using the open method of PIL.Image (named Img) b. Using the Image method from the IPython.core.display module """ # 1. Take the pic of a heart from IPython.core.display import Image , display from PIL import Image as Img heart = 'img/heart.png' display ( Image ( heart )) display ( Img . open ( heart )) # 2. Create an image blanck the size of a card 90*130 # 3. Paste the heart in the middle #...

Let's draw a circle with PIL in Python

Let's continue making our coding around PIL. Let's start with some basic drawing: a circle from PIL import Image , ImageDraw img = Image . new ( "RGB" ,( 60 , 60 ), 'white' ) dr = ImageDraw . Draw ( img ) dr . ellipse (( 0 , 0 , 60 , 60 ), 'yellow' ) img . show () this is the image produced *If you use jupyter notebook, just write img at the end to see the output.