Python Forum
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
roulette game
#1

Hi. i have a homework to create a roulette where it has a few changes from the ordinary. The roulette is an endless loop which generates a number.
-If number is between 1-17 then it will print that the number is small
-If number is between 18-36 then it will print that the number is big
-if it is black or white
-if it is odd or even
the program runs until the user presses q to quit. otherwise it says next run and it generates a new number
here is my code and i need your help to make it work please, since i messed it a lot.
import random

red = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35]
black = [2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36]
green=[0]
number=random.randrange(0,37)

while color != 'q':
    
    color = input("Please choose a color \nor press 'q' to stop the game: ")

color=input('Please choose a color: ')

if 1=>number<=17:
	print('Number is small: ', number)
	else:
		if 18<=number<=36:
			print('Number is big: ',number)


 if number < 0 or number > 36:
        print('Please play again')
    else:
        if number == 0:
            print('Zero has been drawn from the roulette!')
        elif (0 < number <= 10 and number % 2 == 1) or \
             (11 <= number <= 18 and number % 2 == 0) or \
             (19 <= number <= 28 and number % 2 == 1) or \
             (29 <= number <= 36 and number % 2 == 0):                         
            print('Number', number, 'is red.')
        else:
            print('Number', number, 'is black.')
please for your help.
Reply
#2
Maybe this helps:

#!/usr/bin/python3
import random
red   = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35]
black = [2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36]

while True:
    if input("press 'q' to stop the game or return to continue: ") == 'q':
        break
    number = random.randrange(0, 37)
    print('\nNumber is: ', number)

    if 1 <= number <= 17:
        print('Number is small')
    if number in red:
        print('Number is red')
   #if ....
   #if ...
Reply
#3
thanks a lot for the reply heiner55. Regarding the if statements. how can i make it more effecient instead of having multiple if? i have to check color, odd/even, small/big and all have to be printed in one sentence.
in case of number being zero then print 'Zero has been chosen.'

here is my attempt to create it, but it returns errors for spaces and intetation, but i cannot see where it is wrong.
import random
red   = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35]
black = [2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36]
 
while True:
    if input("Press enter to continue or 'q' to end the game: ") == 'q':
        break
    number = random.randrange(0, 37)
    print('\nNumber is: ', number)
 
    if 1 <= number <= 17:
        print('Number is small')
    else:
	print('Number is big')
    if number in red:
        print('Number is red')
    else:
		print('number is black')
    if number % 2 == 0: 
		print('Number is even ')
    else: 
		print('Number is odd')
is this correct? My other concern is how can i have all the answers in one line instead of multiple lines.
Reply
#4
I think the lists and some comparisons can be gotten rid of.

if number % 2 == 0:
    print("Number is even and number is black")
else:
    print("Number is odd and number is red")
Reply
#5
txt = 'Number is: ' + str(number)
...
txt = txt + " and is red"
...
txt = txt + " and is green"
...
print(txt)
Reply
#6
Thanks for your replies. regarding the spacing and indetation what am i doing wrong and it prints out errors in the aforemetnioned code?

please ignore my previous post. everything works fine.
Reply
#7
That is fine to hear.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020