In: Computer Science
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
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.