Fruit Machine Python

Posted on
  1. Fruit Machine Python Download
  2. Fruit Machine Python Programming
  3. Fruit Machine Python Game

Slot Machine in Python. GitHub Gist: instantly share code, notes, and snippets. Sourcing Guide for Fruit Machine: A complete one stop sourcing platform for packaging & printing suppliers, manufacturers and factories, we are big enough to be able to offer an expanded product line of labels and packaging design capabilities yet small enough to be able to provide the personal service that is still so very important in business today. If you don't have Python 3.4 or later you'll have to make your own homegrown Enum class, or use something like def enum (.sequential,.named): enums = dict (zip (sequential, range (1, len (sequential) + 1)),.named) return type ('Enum', , enums) Reel = enum ('CHERRY', 'LEMON', 'ORANGE', 'PLUM', 'BELL', 'BAR', 'SEVEN'). Hi, i was working on a code for a vending machine and i do consider myself to be a beginner, anyway i feel my code is much longer than it needs to be and i want someone to show me a new, shorter way of presenting it. Import time print ('Welcome to the Python Vending Machine.' ) # Asking the user how.

SlotMachine
Fruit
import random
print(''Welcome to the Slot Machine Simulator
You'll start with $50. You'll be asked if you want to play.
Answer with yes/no. you can also use y/n
No case sensitivity in your answer.
For example you can answer with YEs, yEs, Y, nO, N.
To win you must get one of the following combinations:
BARtBARtBARttpayst$250
BELLtBELLtBELL/BARtpayst$20
PLUMtPLUMtPLUM/BARtpayst$14
ORANGEtORANGEtORANGE/BARtpayst$10
CHERRYtCHERRYtCHERRYttpayst$7
CHERRYtCHERRYt -ttpayst$5
CHERRYt -t -ttpayst$2
'')
#Constants:
INIT_STAKE = 50
ITEMS = ['CHERRY', 'LEMON', 'ORANGE', 'PLUM', 'BELL', 'BAR']
firstWheel = None
secondWheel = None
thirdWheel = None
stake = INIT_STAKE
def play():
global stake, firstWheel, secondWheel, thirdWheel
playQuestion = askPlayer()
while(stake != 0 and playQuestion True):
firstWheel = spinWheel()
secondWheel = spinWheel()
thirdWheel = spinWheel()
printScore()
playQuestion = askPlayer()
def askPlayer():
''
Asks the player if he wants to play again.
expecting from the user to answer with yes, y, no or n
No case sensitivity in the answer. yes, YeS, y, y, nO . . . all works
''
global stake
while(True):
answer = input('You have $' + str(stake) + '. Would you like to play? ')
answer = answer.lower()
if(answer 'yes' or answer 'y'):
return True
elif(answer 'no' or answer 'n'):
print('You ended the game with $' + str(stake) + ' in your hand.')
return False
else:
print('wrong input!')
def spinWheel():
''
returns a random item from the wheel
''
randomNumber = random.randint(0, 5)
return ITEMS[randomNumber]
def printScore():
''
prints the current score
''
global stake, firstWheel, secondWheel, thirdWheel
if((firstWheel 'CHERRY') and (secondWheel != 'CHERRY')):
win = 2
elif((firstWheel 'CHERRY') and (secondWheel 'CHERRY') and (thirdWheel != 'CHERRY')):
win = 5
elif((firstWheel 'CHERRY') and (secondWheel 'CHERRY') and (thirdWheel 'CHERRY')):
win = 7
elif((firstWheel 'ORANGE') and (secondWheel 'ORANGE') and ((thirdWheel 'ORANGE') or (thirdWheel 'BAR'))):
win = 10
elif((firstWheel 'PLUM') and (secondWheel 'PLUM') and ((thirdWheel 'PLUM') or (thirdWheel 'BAR'))):
win = 14
elif((firstWheel 'BELL') and (secondWheel 'BELL') and ((thirdWheel 'BELL') or (thirdWheel 'BAR'))):
win = 20
elif((firstWheel 'BAR') and (secondWheel 'BAR') and (thirdWheel 'BAR')):
win = 250
else:
win = -1
stake += win
if(win > 0):
print(firstWheel + 't' + secondWheel + 't' + thirdWheel + ' -- You win $' + str(win))
else:
print(firstWheel + 't' + secondWheel + 't' + thirdWheel + ' -- You lose')
play()

commented Dec 14, 2015

Fruit Machine Python Download

Instead of;
if(answer 'yes' or answer 'y'):

Do;
if answer.lower() in ['yes',y']

commented Jun 2, 2017

I run it on python 2 ,it's need to modify the 43 line (input -> raw_input)

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Fruit Machine Python Programming

Oct-17-2017, 07:17 PM
I need to make a fruit machine in Python. The fruits/items spinning are Cherry, Lemon, Bell, Star and Skull. The Success criteria is •
• If two symbols are rolled the user wins 50p.
• If two skulls are rolled user loses £1, if three skulls are rolled loses all money.
• If you get 3 of the same you get £1, if 3 bells rolled £5.
• Starts with £1, each go costs 20p.


Every time I run the code and I get two of the same items it doesn't add 50p to the credit or add £1 and the credit doesn't properly show for example ... if 1 go costs 20p and I start off with £1 that's 80p. But when I win 50p the new credit should be £1.30 which is not the case. I need help fixing and improving my code.
Oct-17-2017, 07:44 PM
Line 37 should use 'and' instead of 'or'. Think about it: for that to be False, start would have to be 'quit' and 'roll' at the same time, which is impossible (for a string). It's continuing every time through the loop, and never checking the results.
You should also move the if block starting at line 42 and ending at line 44. As it is now, if you have enough money for one last spin, it will just take that money but it won't spin.
Craig 'Ichabod' O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Oct-17-2017, 07:56 PM
Quote:

Each time you roll, you reset the credit to 1. If you want that to persist, set it before you start looping.

Fruit Machine Python Game

Users browsing this thread: 1 Guest(s)
Python