Вы можете полностью отбросить его как параметр.
A python модуль ведет себя очень похоже на одноэлементный класс. Модуль, как и класс, является объектом. all_dice
является атрибутом модуля и, следовательно, доступен для функций, относящихся к тому же модулю.
import random
from random import randint
x = 0
the_dice_chosen = ""
##this is the dictionary
all_dice = {"six":
[["_____",],
["0 0",],
["0 0",],
["0 0",],
["_____",],],
"five":
[["_____",],
["0 0",],
[" 0 ",],
["0 0",],
["_____",],],
"four":
[["_____",],
["0 0",],
[" ",],
["0 0",],
["_____",],],
"three":
[["_____",],
["0 ",],
[" 0 ",],
[" 0",],
["_____",],],
"two":
[["_____",],
["0 ",],
[" ",],
[" 0",],
["_____",],],
"one":
[["_____",],
[" ",],
[" 0 ",],
[" ",],
["_____",],],}
## This prints the dictionary of the numbers chosen side by side.
## Again "all_dice" is passed as "ad" and is used.
def dice_print(ndy,ndz):
x = 0
nday = all_dice[ndy]
ndaz = all_dice[ndz]
for i in nday:
print(nday[x], ndaz[x])
x = x + 1
##This creates the random dice numbers.
def dice_roller():
x = randint(1, 6)
y = randint(1, 6)
return(x, y)
## This converts the numbers into selections in the dictionary. E.G. 6 into "six" "all_dice" is ad
## and it will from now on be passed as "ad".
def dice_maker():
master = {1 : "one",
2 : "two",
3 : "three",
4 : "four",
5 : "five",
6 : "six",}
for i in range(1,2):
x = dice_roller()
y = int(x[0])
z = int(x[1])
new_die_y = (master[y])
new_die_z = (master[z])
dice_print(new_die_y,new_die_z)
##This calls the script to action and passing the dictionary "all_dice"
dice_maker()
Ключевое слово global
Если вам требуется переназначить all_dice
в функция. Вы должны добавить global all_dice
к функции.
all_dice = None
def set_all_dice(value):
global all_dice
all_dice = value
def _set_all_dice(value):
all_dice = value ## all_dice here is scoped to the function