option1 = ['cherry','lemon','orange','plum','bell','bar','7']
option2 = ['cherry','lemon','orange','plum','bell','bar','7']
option3 = ['cherry','lemon','orange','plum','bell','bar','7']
count = 0
while True:
game = str(input('if you want to start a game press y, if you want to back out press n\n'))
if game == 'y':
result1 = print(random.sample(option1,1))
result2 = print(random.sample(option2,1))
result3 = print(random.sample(option3,1))
playercoin = open('playercoin.txt','w')
coin = 10 - count - 1
print(coin, file=playercoin)
playercoin.close()
machinecoin = open('machinecoin.txt','w')
count = count +1
print(slotcoins + count, file=machinecoin)
machinecoin.close()
if result1 == 'cherry':
playercoin = open('playercoin.txt','w')
cherrywin = coins + 2
print(coins, file=playercoin)
playercoin.close()
print('you have won 2 coins')
我正在尝试创建一个运行老虎机的程序,但是我无法让程序在result1
获取项目cherry
时识别。它只是继续循环。
答案 0 :(得分:0)
这样的事情:
game = str(input('if you want to start a game press y, if you want to back out press n\n'))
if game == 'y':
# Since you are after one value i.e. cherry why not use choice function
result1 = random.choice(option1)
result2 = random.choice(option2)
result3 = random.choice(option3)
print([result1, result2, result3]) # You can print them all together
# Or use sample to get all 3 results at once
options = ['cherry', 'lemon', 'orange', 'plum', 'bell', 'bar', '7']
results = random.sample(options, 3)
print(results)
print(results[0]) # will print result1