我正在练习用python编写代码,我目前的项目是一个游戏。所以我正在尝试创建一个控制台游戏,它可以打印混洗的字母,玩家必须使用这些字母创建一个单词。我的计划是有一个不同的层次。每一级,我有不同的随机字母集
这是我的密码:
class Node:
def __init__(self, key):
self.left = None
self.right = None
self.val = key
def printPreorder(root):
if root:
print(root.val),
printPreorder(root.left)
printPreorder(root.right)
class stack:
def __init__(self):
self.items = []
def push(self, item):
return self.items.append(item)
def size(self):
return len(self.items)
#1st possible set for level 1
print('WELCOME TO LEVEL 1')
print ("Create 3 words using the letters:")
root = Node('n')
root.right = Node('o')
root.left = Node ('w')
printPreorder(root)
s1 = stack()
while (s1.size() <3):
FirstList = (input("Enter the word you created: ")).lower()
if FirstList == 'won' or FirstList == 'own' or FirstList == 'now':
s1.push(FirstList)
print(s1.items)
#2nd possible set for level 1
print('WELOCME TO LEVEL 1!')
print ("Create 3 words using the letters:")
root = Node('a')
root.right = Node('r')
root.left = Node ('e')
printPreorder(root)
s1 = stack()
while (s1.size() <3):
SecondList1 = (input("Enter the word you created: ")).lower()
if SecondList == 'ear' or SecondList == 'are' or SecondList == 'era':
s1.push(SecondList)
print(s1.items)
如何在两者之间随机打印/使用一个
您可以使用
random.choice
变量
selected_list
将随机为FirstList或SecondList。您可以将任意数量的列表传递到函数中相关问题 更多 >
编程相关推荐