-1

I'm working on a python program where it would analyze two cards the user inputs. There are (based off research) 169 different possibilities of the first two cards you can get, without specific suits. For example, an ace and a king together is the 3rd best pair if they are same suit, but 5th best pair if there are different suit.

Here's what my code looks like now:

    suit = str(input("suit 1"))
    rank = int(input("rank 1"))
    suit1 = str(input("suit 2"))
    rank1 = int(input("rank 2")) 

if rank == rank1:
    if rank and rank1 == 13: # double ace
        print("1/169")
    elif rank and rank1 == 12: # double king
        print("2/169")
    elif rank and rank1 == 11: # double queen
        print("3/169")
    elif rank and rank1 == 10: # double jack
        print("5/169")
    elif rank and rank1 == 9: # double 10s
        print("10/169")
    elif rank and rank1 == 8: # double 9s
        print("17/169")
    elif rank and rank1 == 7: # double 8s
        print("21/169")
    elif rank and rank1 == 6: # double 7s
        print("29/169")
    elif rank and rank1 == 5: # double 6s
        print("36/169")
    elif rank and rank1 == 4: # double 5s
        print("46/169")
    elif rank and rank1 == 3: # double 4s
        print("50/169")
    elif rank and rank1 == 2: # double 3s
        print("52/169")
    elif rank and rank1 == 1: # double 2s
        print("51/169")

And then basically the same thing with different suits and ranks. Obviously this isn't the best way to do this, and I'm not the best Python coder, but is there any other more efficient way to do this?

Arnav H
  • 11
  • [Near duplicate](https://stackoverflow.com/questions/20002503/why-does-a-b-or-c-or-d-always-evaluate-to-true)... (I guess) – user202729 May 21 '18 at 13:19
  • Also ---- please explain what's wrong with your code (input, current output, expected output) -- see the [mcve] page for more details. If your code already working as expected try [codereview.se] (but remember to read their help before asking) – user202729 May 21 '18 at 13:20

2 Answers2

0

Your code works, but we can improve it a bit by writing less code and code that is easier replicated for the rest of the combinations of pocker. Try this:

suit = str(input("suit 1"))
rank = int(input("rank 1"))
suit1 = str(input("suit 2"))
rank1 = int(input("rank 2"))

scoring_of_doubles = [ [1,51], [2,52], [3,50], [4,46], [5,36], [6,29], [7,21], [8,17], [9,10], [10,5], [11,3], [12,2], [13,1] ]

if rank == rank1:
    for sublist in scoring_of_doubles:            
        if sublist[0] == rank:
            print("You've got a double, scored at: ")
            print(sublist[1])
A. Cloete
  • 69
  • 6
0

I suggest you use dict to keep thins organized:

output = {1: 51,
          2: 52,
          3: 50,
          4: 46,
          5: 36,
          6: 29,
          7: 21,
          8: 17,
          9: 10,
          10: 5,
          11: 3,
          12: 2,
          13: 1}

if rank == rank1:
    print("{}/169".format(output[rank]))
zipa
  • 27,316
  • 6
  • 40
  • 58