Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A slot machine, also known as a one armed bandit, has three wheels that rotate independently. Each wheel contains the same set of symbols. When

A slot machine, also known as a one armed bandit, has three wheels that rotate independently. Each wheel contains the same set of symbols. When a lever is pulled each wheel rotates a random amount and then stops, displaying a sequence of three symbols.

For example suppose each wheel contains the symbols @, #, $, * . When the lever is pulled the sequence displayed might be #@*. If the lever is pulled again *$@ might be displayed. If three identical symbols such as $$$ are displayed you win.

The purpose of this question is to write a python program that finds and displays all the different sequences of the symbols, counts and displays the number of winning sequences and the total number of sequences of the symbols.

Write a function that begins with the following header:

def getSymbols():

This function creates and returns a list of symbols entered by the user. In a loop input the number of symbols from the user. If the value entered by the user is less than or equal to zero display the value entered followed by the message 'must be > 0'. Exit the loop when the value is greater than zero.

In a loop input a symbol from the user and add it to the list of symbols. The loop must be executed once for each symbol. Exit the loop when the correct number of symbols have been entered by the user.

Return the list of symbols.

Write a function that begins with the following header:

def generateSequences(symbols):

This function is given a list of symbols and creates and returns a list of the different sequences of the symbols, one entry in the list for each sequence of symbols. You will need to use nested for loops to create the list of sequences of symbols.

For example if the symbols are #, $, and * then the first sequence of symbols is ###, the next sequence is ##$ and the last sequence is ***.

Return the list of sequences of symbols.

Write a function that begins with the following header:

def countWinners(sequences):

This function is given the list of sequences of symbols and returns the number of winning sequences. A sequence is a winner if all of the symbols in the sequence are the same.

Return the number of winning sequences.

Write a function that begins with the following header:

def displaySequences(sequences):

This function is given the list of sequences of symbols and displays the heading 'The sequence of symbols are:' followed by the sequences one sequence per line. The format of the output is shown in the sample output.

Write a function that begins with the following header:

def main():

This function:

calls getSymbols to get the list of symbols entered by the user

calls generateSequences to get the list of sequences

calls displaySequences to display the sequences

calls countWinners to get the number of winners

displays the number of winners and the total number of sequences

calls displayTerminationMessage to display the termination message

The main program (not to be confused with a function named main) should contain the function definitions, any import statements needed by the functions and a call to the function named main.

Anyone can solve this problem in python.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Demystifying Databases A Hands On Guide For Database Management

Authors: Shiva Sukula

1st Edition

8170005345, 978-8170005346

More Books

Students also viewed these Databases questions

Question

d. How were you expected to contribute to family life?

Answered: 1 week ago