私がこれを持っている場合:
def oneFunction(lists):
category=random.choice(list(lists.keys()))
word=random.choice(lists[category])
def anotherFunction():
for letter in word: #problem is here
print("_",end=" ")
以前に を定義lists
したので、oneFunction(lists)
完全に機能します。
私の問題は 6 行目の呼び出しです。最初の関数の外側で同じ定義word
を定義しようとしましたが、呼び出しても常に同じになります。word
word=random.choice(lists[category])
word
oneFunction(lists)
最初の関数を呼び出してから 2 番目の関数を呼び出すたびに、異なるword
.
word
の外でそれを定義せずにこれを行うことはできますoneFunction(lists)
か?