Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is the question number 9 from chapter 3 of the book \"Starting out with Pyt

ID: 3673798 • Letter: T

Question

This is the question number 9 from chapter 3 of the book "Starting out with Python, Third Edition"                          *I need the answer in Python*

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

Pocket 0 is green

For pocketes 1 through 10. the odd-numberred pockets are red and the even-numbered pockets are black

for pocketes 11 through 18, the odd- numbered pockets are black and the even-numbered pockets are red

for pocketes 19 through 28, the odd-numbered pockets are red and the even-numbered pockets are black

for pocketes 29 through 36, the odd-numbered pockets are black and the even -numbered pockets are red

Write a program that asks the user to enter a pocket number and display whether the pocket is green, re, or black. The program should display an error messege if the user enters a number that is outside the range of 0 through 36.

Explanation / Answer

# Get the number of the pocket
   pocket = int(input('What is the number of the pocket: '))
  
   # Determine the color

   green = 0

   red = [1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36]

   black = [2, 4, 6, 8, 10, 11, 13, 15, 17, 20, 22, 24, 26, 28, 29, 31, 33, 35]

  

   # Display the color of the pocket

   if pocket in green:

        print('The pocket color is green.')

   elif pocket in red:

        print('The pocket color is red.')

   elif pocket in black:

        print('The pocket color is black.')

   else:

        print('There is not a pocket with that number')

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote