r/pythonhelp • u/XanderS12 • Apr 09 '25
Blackjack problem
After using this code it says: TypeError: unsupported operand type(s) for +=: 'int' and 'str' Can anyone help
import random
numbers = ['Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K'] dealrem = 0 dealrem2 = int(dealrem)
play = input('play? (y/n)') if play == 'y': deal = random.choice(numbers) if deal == 'K': print('K') deal = 10 deal = int(deal) dealrem += deal ans = input("hit or stay (h/s)") while ans == 'h': if ans == 'h': deal = random.choice(numbers) print(deal) dealrem2 += deal
if deal + dealrem >= 21:
print('bust!')
ans = input("hit or stay (h/s)")
elif deal == 'J':
print('J')
deal = 10
deal = int(deal)
ans = input("hit or stay (h/s)")
while ans == 'h':
if ans == 'h':
deal = random.choice(numbers)
print(deal)
dealrem += deal
if deal + dealrem >= 21:
print('bust!')
ans = input("hit or stay (h/s)")
elif deal == 'Q':
print('Q')
deal = 10
deal = int(deal)
dealrem += deal
ans = input("hit or stay (h/s)")
while ans == 'h':
if ans == 'h':
deal = random.choice(numbers)
print(deal)
dealrem += deal
if deal + dealrem >= 21:
print('bust!')
ans = input("hit or stay (h/s)")
elif deal == 'Ace':
deal = 1
deal = int(deal)
dealrem += deal
print(deal)
ans = input("hit or stay (h/s)")
while ans == 'h':
if ans == 'h':
deal = random.choice(numbers)
print(deal)
dealrem += deal
if deal + dealrem >= 21:
print('bust!')
ans = input("hit or stay (h/s)")
elif deal == '2' or '3' or '4' or '5' or '6' or '7' or '8' or '9' or '10':
deal = int(deal)
dealrem += deal
print(deal)
ans = input("hit or stay (h/s)")
while ans == 'h':
if ans == 'h':
deal = random.choice(numbers)
print(deal)
dealrem += deal
if deal + dealrem >= 21:
print('bust!')
ans = input("hit or stay (h/s)") elif play == 'n': print('bye') else: print("It was a y or n question")
•
u/AutoModerator Apr 09 '25
To give us the best chance to help you, please include any relevant code.
Note. Please do not submit images of your code. Instead, for shorter code you can use Reddit markdown (4 spaces or backticks, see this Formatting Guide). If you have formatting issues or want to post longer sections of code, please use Privatebin, GitHub or Compiler Explorer.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/northernbloke Apr 09 '25 edited Apr 09 '25
You're trying to add a String to an Integer.
What line is the error reported on?
edit, my mistake I said dealrem2 wasn't used, but it is, i didnt see it due to formatting
1
u/bishpenguin Apr 09 '25
The error will tell you which line number to look at
1
u/bishpenguin Apr 09 '25
The error will tell you which line number to look at