Higher or lower error message

Hello guys, I am trying to simulate a card game where you have to pick the higher card than the function to win, however I am trying to use a list but everytime I go to run it, this error message comes up:

Traceback (most recent call last):
  File "script.py", line 80, in <module>
    print(higher_lower(10, 30))
  File "script.py", line 46, in higher_lower
    if guess > List1:
TypeError: '>' not supported between instances of 'int' and 'list'

Below is the example code:

def higher_lower(guess, bet):
  global money
  ace = 1
  jack = 11
  queen = 12
  king = 13
  List1 = [ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, jack, queen, king]
  random.choice(List1)
  #Value = random.randint(1, 10)

  if guess > List1:
    money = money + bet
    return "Congratulations, you have picked the higher card and won!\n" + "You now have £" + str(money) + " in your account." 

  elif guess < List1:
    money = money - bet
    return "Unfortunately you haven't picked the higher card and lost this time!\n" + "You now have £" + str(money) + " in your account." 

  else:
    money
    return "You have picked a card with the same value as your opponent, it is a tie!\n" + "You now have £" + str(money) + " in your account."

any clue on how to fix it?

Thankyou in advance

Your conditional is checking between guess which you haven’t included the code but it’s apparently an integer and List1 which is a list. Since there’s no obvious answer for if a number is bigger than a list, e.g. is 3 bigger than [‘Red’, 0.5, print] then an error is thrown instead.

Based on what you expect to happen it seems like when you make your random.choice from List1 you need to take the value that’s returned from that function, store it in a variable and use that as your comparison.

1 Like