0

Still learning python3 and im currently creating a domino game. I'm making progress so far but i haven't been working with functions at all.

My question is: How do i get the domino_stock_set into my split_stones function so i can split it up?

Seems like a dumb question but i googled half an hour and couldn't find anything that would work. I tried anything so at this point i might have several erros in the script.

import random

random_hand = random.randint(0, 7)
random_sixseven = random.randint(6,7)



def stock_set():
    global domino_stock_set
    domino_stock_set = []
    for i in range(0, 7):
        for j in range(i, 7):
            domino_stock_set.append([i, j])
    random.shuffle(domino_stock_set)
    
    print()
    print("…ᘛ⁐̤ᕐᐷ  -Stock Set-  …ᘛ⁐̤ᕐᐷ")
    print(domino_stock_set)
    print()
    return domino_stock_set



def split_stones(domino_stock_set, wanted_parts=1):
    length = len(domino_stock_set)
    return [ domino_stock_set[i*length // wanted_parts: (i+1)*length // wanted_parts] 
             for i in range(wanted_parts) ]

print("==============P L A Y E R==================")
print(split_stones(domino_stock_set, wanted_parts = random_sixseven))

print("=============C O M P U T E R===============")
print(split_stones(domino_stock_set, wanted_parts = random_sixseven))



stock_set()
split_stones()
MKcode
  • 37
  • 3

1 Answers1

0

I would just google for something like "python function arguments". Then you will get results such as e.g. this one.

To apply it to your example:

domino_stock_set = []
split_stones(domino_stock_set)

Furthermore, try to avoid using global variables, see e.g. this SO question. If you use domino_stock_set as a global variable you do not even need to pass it to any function because that variable would be available globally.

flyingdutchman
  • 1,197
  • 11
  • 17