Question

In: Computer Science

4. On a roulette wheel, the pockets are numbered from 0 to 36. The colours of...

4. On a roulette wheel, the pockets are numbered from 0 to 36. The colours of the pockets are as follows:

• Pocket 0 is green.

• For pockets 1 through 10, the odd-numbered pockets are red and the even-numbered pockets are black.

• For pockets 11 through 18, the odd-numbered pockets are black and the even-numbered pockets are red.

• For pockets 19 through 28, the odd-numbered pockets are red and the even-numbered pockets are black.

• For pockets 29 through 36, the odd-numbered pockets are black and the even-numbered pockets are red.

Write a function, pocket_colour that takes an integer as parameter and returns the colour corresponds to the pocket number.

"The function should return the string "Error" if the user enters a number that is outside the range of 0 through 36.

Write a testing program named t04.py that tests your function by asking the user to enter a pocket number and displays whether the pocket is green, red, or black.

A sample run:

Enter a pocket number: 0

The selected pocket is green.

Solutions

Expert Solution

t04.py

'''Function pocket_colour that takes an integer as parameter'''

def pocket_colour(num):

#Condition where Pocket 0 is green
    if num == 0:
        return "Green"

#Condition for pockets 1 through 10 (odd-numbered pockets are red and even-numbered pockets are black)
    elif num >= 1 and num <= 10:
        if(num % 2 == 0):  #Checking whether number is even or not.
            return "Black"
        return "Red"

#Condition for pockets 11 through 18 (odd-numbered pockets are black and even-numbered pockets are red)
    elif num >= 11 and num <= 18:
        if(num % 2 == 0):  # Checking whether number is even or not.
            return "Red"
        return "Black"

#Condition for pockets 19 through 28 (odd-numbered pockets are red and even-numbered pockets are black)
    elif num >= 19 and num <= 28:
        if(num % 2 == 0):  # Checking whether number is even or not.
            return "Black"
        return "Red"

#Condition for pockets 11 through 18 (odd-numbered pockets are black and even-numbered pockets are red)
    elif num >= 29 and num <= 36:
        if(num % 2 == 0):  # Checking whether number is even or not.
            return "Red"
        return "Black"

#Condition to display error if user enter integer outsides the range of 0 through 36.
    else:
        return "Error"


'''Testing Program that tests function pocket_colour and displays output accordingly.'''

def main():
    num = int(input("Enter pocket number: "))  # Converting input string to integer.
    print(pocket_colour(num))

#Invoking main function
if __name__ == "__main__":
    main()

Refer to the code snippet above for a detailed explanation of the solution. The testing program is fairly simple as the function does most of the work. Hence function and testing program can be kept in the same file. Revert back in the comments if you need further clarification. You can copy the code and test directly in an online ide. All the best!


Related Solutions

On a roulette wheel, the pockets are numbered from 0 to 36. The colours of the...
On a roulette wheel, the pockets are numbered from 0 to 36. The colours of the pockets are as follows: • Pocket 0 is green. • For pockets 1 through 10, the odd-numbered pocketsare red and the even-numberedpockets are black. • For pockets 11 through 18, the odd-numberedpocketsare black and the even-numbered pockets are red. • For pockets 19 through 28, the odd-numberedpocketsare red and the even-numberedpockets are black. • For pockets 29 through 36, the odd-numberedpocketsare black and the...
Write a code on Jupytor notebook: On a roulette wheel, the pockets are numbered from 0...
Write a code on Jupytor notebook: On a roulette wheel, the pockets are numbered from 0 to 36. The colors of the pockets are as follows: Pocket 0 is green. For pockets 1 through 10, the odd-numbered pockets are red and the even-numbered pockets are black. For pockets 11 through 18, the odd-numbered pockets are black and the even-numbered pockets are red. For pockets 19 through 28, the odd-numbered pockets are red and the even-numbered pockets are black. For pockets...
A roulette wheel has 38 slots, numbered 0, 00, and 1 to 36. The slots 0...
A roulette wheel has 38 slots, numbered 0, 00, and 1 to 36. The slots 0 and 00 are colored green, 18 of the others are red, and 18 are black.The dealer spins the wheel and at the same time rolls a small ball along the wheel in the opposite direction. The wheel is carefully balanced so that the ball is equally likely to land in any slot when the wheel slows. Gamblers can bet on various combinations of numbers...
A roulette wheel has numbers from 1 to 36 and two "special" numbers 0 and 00....
A roulette wheel has numbers from 1 to 36 and two "special" numbers 0 and 00. A $1 bet on a number will pay $36 if that number comes up. It is also possible to bet on two adjacent numbers, with a $18 payout if one of them spells, or four adjacent numbers, with a $9 payout. a) Let X be the total payout of a $1 bet on a number. Find E(X) and Var(X). b) Let Y be the...
In the game of​ roulette, a wheel consists of 38 slots numbered​ 0, 00,​ 1, 2,...,...
In the game of​ roulette, a wheel consists of 38 slots numbered​ 0, 00,​ 1, 2,..., 36. To play the​ game, a metal ball is spun around the wheel and is allowed to fall into one of the numbered slots. If the number of the slot the ball falls into matches the number you​ selected, you win​ $35; otherwise you lose​ $1. Complete parts ​(a) through ​(g) below (a) Construct a probability distribution for the random variable​ X, the winnings...
You are playing a version of the roulette game, where the pockets are from 0 to...
You are playing a version of the roulette game, where the pockets are from 0 to 10 and even numbers are red and odd numbers are black (0 is green). You spin 3 times and add up the values you see. What is the probability that you get a total of 15 given on the first spin you spin a 2? What about a 3? Solve by simulation and analytically.
In the game of roulette, there is a wheel with 37 slots numbered with the integers...
In the game of roulette, there is a wheel with 37 slots numbered with the integers from 0 to 36, inclusive. A player bets $3 and chooses a number. The wheel is spun and a ball rolls on the wheel. If the ball lands in the slot showing the chosen number, the player receives $3 plus 100$. Otherwise, the player loses the $3 bet. Assume that all numbers are equally likely. Determine the variance of the gain or loss per...
In the popular American game of roulette, the roulette wheel has 38 spaces that are numbered...
In the popular American game of roulette, the roulette wheel has 38 spaces that are numbered 0, 00, and 1 through 36, 0. Find the probability of getting the following: a) A number that is less than 15, not counting 0 and 00; b) A number that is a multiple of 3 or 5, not counting 0 and 00; c) An odd number that is less than 15, not counting 0 and 00; d) A number that is between 1...
A roulette wheel is divided into 38 labeled pockets, 18 of which are red, 18 are...
A roulette wheel is divided into 38 labeled pockets, 18 of which are red, 18 are black, and 2 are green. Each round, you can place a $1 bet on one specific red or black pocket with odds of 35 : 1. That is, if you are correct you receive $35 in addition to the dollar you bet, and if you are incorrect, you get nothing. Your friend has developed what he describes as a “foolproof system” for winning. It...
ROULETTE is a casino game where a numbered wheel spins and a steel ball falls into...
ROULETTE is a casino game where a numbered wheel spins and a steel ball falls into a location marked by one particular colored number. In the United States there are 18 locations colored red, 18 locations colored black and 2 locations colored green. The red and black locations are numbered 1-36 and the green locations are labeled "0" and "00" as shown in the picture to the right. The wheel therefore has 38 locations in total. Note that the odd...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT