Question

In: Computer Science

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 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. Save the function in a PyDev library

module named functions.py

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.

• Test your program with 10 different data, you may assume that the user will only enter

numbers.

• Copy the results to test

Solutions

Expert Solution

functions.py

def pocket_colour(n):
    if n<0 or n>36:
        print("Error")
    else:
        if n==0:
            return 'green'
        if n>0 and n<=10:
            if n%2==0:
                return 'black'
            else:
                return 'red'
        elif n>10 and n<=18:
            if n%2==0:
                return 'red'
            else:
                return 'black'
        elif n>18 and n<=28:
            if n%2==0:
                return 'black'
            else:
                return 'red'
        elif n>28 and n<=36:
            if n%2==0:
                return 'red'
            else:
                return 'black'

t04.py

import functions as f
num=int(input("Enter a pocket number:"))
colour=f.pocket_colour(num)
print("The selected pocket is "+colour+".")

test:

=========================== RESTART: D:/python/t04.py ==========================
Enter a pocket number:0
The selected pocket is green.
>>> 
=========================== RESTART: D:/python/t04.py ==========================
Enter a pocket number:-5
The selected pocket is Error.
>>> 
=========================== RESTART: D:/python/t04.py ==========================
Enter a pocket number:39
The selected pocket is Error.
>>> 
=========================== RESTART: D:/python/t04.py ==========================
Enter a pocket number:3
The selected pocket is red.
>>> 
=========================== RESTART: D:/python/t04.py ==========================
Enter a pocket number:8
The selected pocket is black.
>>> 
=========================== RESTART: D:/python/t04.py ==========================
Enter a pocket number:23
The selected pocket is red.
>>> 
=========================== RESTART: D:/python/t04.py ==========================
Enter a pocket number:28
The selected pocket is black.
>>> 
=========================== RESTART: D:/python/t04.py ==========================
Enter a pocket number:34
The selected pocket is red.
>>> 
=========================== RESTART: D:/python/t04.py ==========================
Enter a pocket number:35
The selected pocket is black.
>>> 
=========================== RESTART: D:/python/t04.py ==========================
Enter a pocket number:17
The selected pocket is black.

Related Solutions

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