Posted  by 

Fruit Machine Python

Tiger777

Jun 23rd, 2016
Never
Machine
Not a member of Pastebin yet?Sign Up, it unlocks many cool features!

Python Fruit Machine - Looping back to input. Hot Network Questions Why does an exponential function eventually get bigger than a quadratic Can I make lemon curd more sour/tart after it's cooked? Is ὀργίζω, to anger, cognate with ὄργια, a secret rite or ritual? Hard temperatures rises for a Mosfet. Slot Machine in Python. GitHub Gist: instantly share code, notes, and snippets. In this challenge we are going to write a Python program that automatically generates six random numbers (from 1 to 50) and display them on the screen, sorted in ascending order. The program will need to make sure that each number is unique; the same number cannot come twice in the selection of six selected numbers. Learning Objectives By completing this code, you will understand the. Submit a list of names, then click to spin the wheel to choose one at random! Save your lists and embed them in your website or blog!

  1. importrandom
  2. cash =float(1)
  3. choice =input('n Type y to play the fruit machine (or r to reset with £1): ')
  4. cash =1
  5. if choice 'y':
  6. print('Sorry, you don't have enough cash to play.')
  7. fruits =['Cherry','Bell','Lemon','Orange','Star','Skull']
  8. print('You have £'+str(round(cash,2))+' credit in the machine.')
  9. print('You lose 20p credit leaving you with £'+str(float(round(cash-0.20,2))))
  10. while roll !='123':
  11. fruit2 ='Skull'
  12. print('Rolling.. n')
  13. print('The first fruit is: '+fruit1)
  14. print('The second fruit is: '+fruit2)
  15. print('The third fruit is: '+fruit3)
  16. if fruit1 fruit2 or fruit1 fruit3 or fruit2 fruit3:
  17. bell=0
  18. total=0
  19. skull = skull+1
  20. bell = bell+1
  21. other = other + 1
  22. if fruit2 'Skull':
  23. elif fruit2 'Bell':
  24. else:
  25. skull = skull + 1
  26. bell = bell + 1
  27. other = other + 1
  28. if skull 2or skull 3:
  29. print('You lose £1 credit!')
  30. else:
  31. cash =0
  32. if fruit1fruit2:
  33. if fruit1fruit3:
  34. if fruit2fruit3:
  35. if total 1:
  36. cash = cash + 0.50
  37. print('You win £1!')
  38. if bell 2:
  39. cash = cash + 1
  40. if bell 3:
  41. cash = cash + 5
  42. elif choice 'r':
  43. print('You lose..')
  44. print('Goodbye')
SlotMachine
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

Machine-Learning-with-Python / fruitdatawithcolors.txt Go to file Go to file T; Go to line L; Copy path Cannot retrieve contributors at this time. 60 lines (60 sloc) 2.31 KB Raw Blame. Fruitlabel fruitname fruitsubtype mass width height colorscore 1 apple grannysmith 192 8.4 7.3 0.55.

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)

Fruit Machine Python Code

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