Home > OS >  How do you see if a value is greater than two others? ex: a=5, b=9, c=1: if a > b & c: print(&quo
How do you see if a value is greater than two others? ex: a=5, b=9, c=1: if a > b & c: print(&quo

Time:08-28

I have been trying to make a black jack game, and have come to a point where three players roll the dice to decide who goes first. I need to check if player_a rolled higher than both player_b & player_c. I tried: if a_roll > b_roll & c_roll:, but that just adds the b and c rolls. I feel like there is an easy way to do this but i cannot figure it out. here is my full program so far:

import random

print("Welcome to Max's BlackJack v1.0")
print("   _____")
print("  |A .  | _____")
print("  | /.\ ||A ^  | _____")
print("  |(_._)|| / \ ||A _  | _____")
print("  |  |  || \ / || ( ) ||A_ _ |")
print("  |____V||  .  ||(_'_)||( v )|")
print("         |____V||  |  || \ / |")
print("                |____V||  .  |")
print("                       |____V|")
print("")
print("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
ready = input("To start type ready: ")
if ready == "ready":
    print("")
    print("")
    mode = input("Single Player(1) or Multiplayer(2)... ")
    if mode == "1":
        print("Hello their Sir, Welcome to Back Jack. ")
        print("")
        print("These are your competitors... ")
        player_a = random.randint(1,3)
        player_b = random.randint(1,3)
        player_c = random.randint(1,3)
#first dude
        if player_a == 1:
            player_a = ("Tessa")
        if player_a == 2:
            player_a = ("Britney")
        if player_a == 3:
            player_a = ("zack")
#seccond dude
        if player_b == 1:
            player_b = ("Donald")
        if player_b == 2:
            player_b = ("Bruce")
        if player_b == 3:
            player_b = ("Colin")
#third dude
        if player_c == 1:
            player_c = ("leven")
        if player_c == 2:
            player_c = ("Joe")
        if player_c == 3:
            player_c = ("Brady")
        print("")
        print(player_a   ","   player_b   ","   player_c)
        print("")
#game code starts here
        start2 = input("Press ENTER ")
        print("DEALER: Lets begin. ")
        print("DEALER: To decide who goes first we each roll the dice, whomever gets the highest number goes first")
        print("")
        a_roll = random.randint(1,12)
        b_roll = random.randint(1,12)
        c_roll = random.randint(1,12)
        print(player_a   " rolled a "   str(a_roll))
        print(player_b   " rolled a "   str(b_roll))
        print(player_c   " rolled a "   str(c_roll))
#filter results
        if a_roll > b_roll & c_roll:
            print("bruh")
        if b_roll > a_roll & c_roll:
            print("test")
        print(a_roll   b_roll)

CodePudding user response:

The & operatior is a "bitwise and" operator which does a logical AND operation on the bits of the numbers. The operator you actually need is "and". The correct way to do this is to first check is a is higher than b and then check if a is higher than c like this:

if a > b and a > c:

CodePudding user response:

I might use if b < a > c: (if I had three variables instead of a list or so and wanted to write separate code for each case, which I almost certainly wouldn't).

  • Related