Python Forum
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
roulette game
#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


Messages In This Thread
roulette game - by atux_null - Oct-28-2017, 12:03 AM
RE: roulette game - by heiner55 - Oct-28-2017, 06:26 AM
RE: roulette game - by atux_null - Oct-28-2017, 05:59 PM
RE: roulette game - by james - Oct-28-2017, 06:21 PM
RE: roulette game - by heiner55 - Oct-29-2017, 05:49 AM
RE: roulette game - by atux_null - Oct-29-2017, 08:59 AM
RE: roulette game - by heiner55 - Oct-31-2017, 08:45 AM

Forum Jump:

User Panel Messages

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