Posted  by  admin

Python Fruit Machine

Python Fruit Machine Rating: 6,4/10 8150 votes

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.

Thanks.

In python, sklearn is a machine learning package which include a lot of ML algorithms. Here, we are using some of its modules like traintestsplit, DecisionTreeClassifier and accuracyscore. NumPy: It is a numeric python module which provides fast maths functions for calculations. It is used to read data in numpy arrays and for manipulation.

Monty Python Fruit Machine

  • 5 Contributors
  • forum5 Replies
  • 12,867 Views
  • 2 Years Discussion Span
  • commentLatest PostLatest Postby Reverend Jim
  1. Tomato fruit is used for the result. There are many different types of tomatoes, in this project rishika 225 tomato species has taken which is available in any season. Key Words: Computer Vision, Python, Fruit image analysis, Fruit quality detection, Classification. INTRODUCTION India is an agriculture country. Different types of fruits.
  2. 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.

Python Fruit Machine Game

Recommended Answers

Before making any suggestions, I would like to ask if your course of study (whether personal or formal) has gotten to functions and how to write them yet. This would be a big factor in how you approach thsis matter.

Python Fruit MachineJump to Post

The first thing is to never have variable names containing a variable index, such as product_1, product_2, etc. Use lists or tuples instead

Then product[0] is …

Jump to Post

All 5 Replies

Schol-R-LEA1,117Commie Mutant Traitor Featured Poster

Before making any suggestions, I would like to ask if your course of study (whether personal or formal) has gotten to functions and how to write them yet. This would be a big factor in how you approach thsis matter.

Machine
Editedby Schol-R-LEA
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

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

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

Fruit machine python program

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