Intro to Programming and Logic (chapter 5):
Python 2 - Conditionals and Recursion:
Write a program that will simulate a roulette wheel. The pockets on a roulette wheel are different colors.
There are 36 pockets – numbered 0 to 35. Pocket 0 and 18 are green.
For pockets 1 – 8, the even numbers are black and the odd numbers are red.
For pockets 9 – 17, the even numbers are red and the odd numbers are black.
For pockets 19 – 27, the even numbers are black and the odd numbers are red.
For pockets 28 – 35, the even numbers are red and the odd numbers are black.
Have the program ask the user for a color. If the color is not “red”, “green”, or “black”- the program should display an error and the program should end. The program will then randomly generate a number from 0 to 35. It will then determine the color for that number. If the color of the randomly picked number and the color picked by the user match – display a message of congratulations. If they do not match, display an error message – along with the color of that pocket that was randomly selected.
Your program should have at least 2 functions. One should be the main. The other should be a function that picks a random number from 0 to 35, displays the number, determines from the rules above what the color that number is, and then returns the color. The color should be string – either “red”, “black”, or “green.
Grading:
Program compiles with no syntax errors: 12 points
The program does what it is supposed to do: 5 points
You have meaningful comments: 3 points
You should have a multiline comment at the top to describe what the program does.
You should have comments that describe what your functions do You should have comments in your program wherever else would be useful to the reader of your code.
## Start of the program ##
from __future__ import print_function
import random # for generating random number
'''
This program will simulate a roulette wheel. The pockets on a roulette wheel are different colors.
There are 36 pockets numbered 0 to 35. Pocket 0 and 18 are green.
For pockets 1 to 8, the even numbers are black and the odd numbers are red.
For pockets 9 to 17, the even numbers are red and the odd numbers are black.
For pockets 19 to 27, the even numbers are black and the odd numbers are red.
For pockets 28 to 35, the even numbers are red and the odd numbers are black.
To Play :
1. User will enter a color - black, green or red. If an invalid color is entered, the program will print an error and exit
2. If a valid color is entered, the program will generate a random number from 0 to 35 and the color assocaited with the random number generated
3. If the color entered by the user matches the generated color, the user win. Otherwise the user looses.
'''
# main method begins
def roulette():
# prompts the user to enter a color and store it
# NOTE : Please replace raw_input with input function if you're running this in Python3
userSelectedColor = raw_input("Enter a color (black, green or red) : ")
# if entered color is invalid, show error message
if userSelectedColor.lower() != "green" and userSelectedColor.lower() != "red" and userSelectedColor.lower() != "black":
print("Error : Please pick a color from black, green or red only")
# if entered color is valid, call play method to generate a color
else:
generatedColor = play()
# if entered color matches the generated color, print win message
if userSelectedColor.lower() == generatedColor:
print("Congrats you win")
# if entered color doesn't match the generated color, print message for loosing and the generated color
else:
print("Sorry! You loose. Color of the pocket is ", generatedColor)
'''
play method to generate a random number and the corresponding color.
returns the generated color
'''
def play():
# generates a random number between 0 and 35
pocket = random.randrange(0, 35)
# prints the random number generated
print("Random number is :", pocket)
# start of if condition to set the generated color according to the random number generated
if pocket == 0 or pocket == 18:
color = "green"
elif(pocket >= 1 and pocket <= 8):
if(pocket%2 == 0):
color = "black"
else:
color = "red"
elif(pocket >= 9 and pocket <= 17):
if(pocket%2 == 0):
color = "red"
else:
color = "black"
elif(pocket >= 19 and pocket <= 27):
if(pocket%2 == 0):
color = "black"
else:
color = "red"
elif(pocket >= 28 and pocket <= 35):
if(pocket%2 == 0):
color = "red"
else:
color = "black"
# returns the color
return color
'''
Calling the main method roulette
'''
roulette()
## End of the program ##
SCREENSHOTS :
In Python2

In Python3

Intro to Programming and Logic (chapter 5): Python 2 - Conditionals and Recursion: Write a program...
programming language: C++ *Include Line Documenatations* Overview For this assignment, write a program that will simulate a game of Roulette. Roulette is a casino game of chance where a player may choose to place bets on either a single number, the colors red or black, or whether a number is even or odd. (Note: bets may also be placed on a range of numbers, but we will not cover that situation in this program.) A winning number and color is...
QuestionI the casino gambling game of American Roulette the wheel has 38 pockets numbered 00,0,1..36. Half of the numbers from 1 and 36 are painted black, while the others are painted red. The numbers 00 and 0 are painted green. A ball is equally likely to land in any pocket. Listed below are several of the many possible bets on where the ball lands, together with their winning payouts based on a 81 stake. In each case calculate the expected...
Intro to Programming and Logic: Python 2, Chapter 8 – Strings (so far have learned the way of a program, variables, expressions, statements, functions, interface design, conditional, recursion and iteration) Write a program that takes a string as a parameter. It will analyze the string and return True if it is a valid float number. It will return False if it is not a valid float value. Your function should return True in any of these cases: 0.17, .17, 5.27,...
Please
Home Chapter 3 Use the following information to answer the next three exercises. The casino game, roulette, allows the gambler to bet on the probability of a ball, which spins in the roulette wheel, landing on a particular color, number, or range of numbers. The table used to place bets contains of 38 numbers, and each number is assigned to a color and a range. Ist Dozen 2nd Dozen 3rd Dozen 1 to 18 EVEN ODD 19 to 36...
In the casino gambling game of American Roulette the wheel has 38 pockets numbered 00,0,1, . . . ,36. Half of the numbers from 1 and 36 are painted black, while the others are painted red. The numbers 00 and 0 are painted green. A ball is equally likely to land in any pocket. Listed below are several of the many possible bets on where the ball lands, together with their winning payouts based on a$1 stake. In each case...
A roulette wheel has 38 numbers, with 18 odd numbers (black) and 18 even numbers (red), as well as 0 and 00 (which are green). If you bet $19 that the outcome is an odd number, the probability of losing the $19 is 20/38 and the probability of winning is $38 (for a net gain of only $19, given you already paid $19) is 18/38. If a player bets $19 that the outcome is an odd number, what is the...
4.28 An American roulette wheel has 18 red numbers, 18 black numbers, and 2 gree Assume all numbers are equally likely a. What is the probability the number is red? Black? Green? b. The player can make simple bets on the color. A dollar bet on red or blac n numbers. k returns a dollar the variance of this bet? profit if red or black comes up. What is the expected value of this bet? What is c Abet on...
Question 2.9
lt Wieelr With a bet of $5 on black and a bet of $2 on the specific group of four numbers pictured in Figure 2.1 (13, 14, 16, 17). What is the bettor's expectation on this combined bet? Conclude, as suggested in the text, that the bettor's expected loss is 5.26 cents for every dollar bet. 2.9 A European roulette wheel has 37 sectors including a zero but no double zero. Furthermore if the zero comes up, any...
Write this is Java. The program will randomly select a color from one of the 5 green red blue yellow orange. And ask you to guess which was randomly selected. It will select a random color by choosing a random number from 0-4 0 can represent green and 1 red. It will ask you to guess the color randomly selected and reveal what it chose after you guessed. After it will do the same 10 times loop and will display...
Write a c++ complete program to meet the specifications. The program should prompt the user for a positive integer. The program should print a message whether the integer is even or odd. The looping should end when the user enters a negative number. The negative number will not be tested for even or odd. The program will print out a message of how many numbers were entered (not counting the negative number) and how many even and odd numbers were...