This is a small experiment I am trying in learning Python. Its meant to be a text based slot machine, where 3 slots are 'rolled' and 1 of the 4 possible choices is chosen for each If the 2 numbers match, 5 points are given. If all 3 match, 10 are given. After running this function the game prints their current score asks if the user wants to play again. At this portion of the code:
def ask():
play_again = raw_input ("Do you want to play again? (Yes or No):")
if play_again == "yes" or "Yes":
run_machine()
elif play_again == "No" or "no":
print "Bye!"
sys.exit(1)
else:
print "I don't know what that means"
ask()
Where run_machine() is the main function. However regardless of the input, the program repeats. I am new to python so this might be something simple but I wanted to see what so far might be the problem. If it isn't something in this block then here is the full program:
import random
slot_1 = [1,2,3,4]
slot_2 = [1,2,3,4]
slot_3 = [1,2,3,4]
points = 0
def role(slot):
return (random.choice(slot))
def run_machine():
print "ROLLING!"
first = role(slot_1)
second = role(slot_2)
third = role(slot_3)
global points
if (first == second) or (first == third) or (second == third):
if (first == second) and (second == third):
print "You got 10 points! Full matches!"
points = points + 10
else:
print "You got 5 points, 2 matched!"
points = points + 5
else:
print "Sorry try again!"
print "You now have %s points" % points
ask()
def ask():
play_again = raw_input ("Do you want to play again? (Yes or No):")
if play_again == "yes" or "Yes":
run_machine()
elif play_again == "No" or "no":
print "Bye!"
else:
print "I don't know what that means"
ask()
run_machine()