4/15/2022

Fruit Machine Python

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'). Fruita, fruitb, fruitc = allfruit I think single letter variable names (excluding and loop counters) should be avoided at all costs. You currently have all the fruits values hard coded in, it might be worth while to extract that data into a file to make it easier to add/remove new ones.

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.

  • 5 Contributors
  • forum5 Replies
  • 12,867 Views
  • 2 Years Discussion Span
  • commentLatest PostLatest Postby Reverend Jim

Recommended Answers

Machine

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.

Jump 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.

Fruit Machine Python Programming

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

Users browsing this thread: 1 Guest(s)

Fruit Machine Code Python