# Error in a project "games of chance"

below is the code

``````import random

money = 100
#num = random.randint(1, 10)
#Write your game of chance functions here
tails = 2

def coin_flip(bet_money,call):
if bet == call:
return bet_money
else:
return -bet_money
#print(money)

#Call your game of chance functions here
#cho_han
dice_1 = random.randint(1,6)
dice_2 = random.randint(1,6)
dice_sum = dice_1 + dice_2

def cho_ban(call,bet):
if dice_sum%2 == 0 and call == "even":
return bet
if dice_sum%2 != 0 and call == "odd":
return bet
else:
return -bet
print(cho_ban("even",20))
#money += cho_ban("even",20)
#print(money)

#card-game

def card_game(p1_bet,p2_bet):
p1 = random.randint(1,10)
p2 = random.randint(1,10)
if p1>p2:
return p2_bet
elif p2>p1:
return 0-p1_bet
else:
return 0
print(card_game("10","15"))
#money += card_game("10","15")
#print(money)

#roulette
r_num = random.randint(0,100)

def roulette_guess(guess,bet_r):
if r_num%2 ==0 and guess == "even":
return bet_r*2
elif r_num%2 != 0 and guess == "odd":
return bet_r*2
elif r_num == guess:
return r_num * 35
elif r_num == 0:
return -r_num
else:
return -r_num

print(roulette_guess("odd",6))
``````

ERROR:
Traceback (most recent call last):
File “script.py”, line 49, in
print(card_game(“10”,“15”))
File “script.py”, line 46, in card_game
return -p1_bet
TypeError: bad operand type for unary -: ‘str’

Hello, @codeninja16991. Welcome to the forum. Please read the following regarding posting code, so we can view it properly.

Code that is posted without the indentations preserved, is not Python. Indentations are not optional in Python, but are rather an essential part of the language , lacking which your code will not run at all.

Unindented code is difficult to read, requires guesswork concerning your intent, and cannot be copied and pasted for testing, both because it is unindented and because it often contains characters such as left-and right double-quotes that are unreadable to the Python interpreter.

The Codecademy forum provides a quick and easy way to post properly-formatted code. All you need to do is look for the </> icon in the menu bar which appears at the top of the text box while you type.

Press Enter to go to a blank line, click that icon, and you will see this:

Just copy and paste your code directly from the editor into that highlighted portion, and all of the nicely-readable Python formatting will be preserved! Moreover, it will be in a format that can be directly copied and pasted into a Python IDE for testing.

The same icon can be used for highlighting small code snippets in-line for clarity.

1 Like

here:

``````return 0-p1_bet
``````

p1_bet is a string, integer minus string does not go well. Looking at the function call:

``````print(card_game("10","15"))
``````

i can see where the strings come from. The arguments should be integers.

1 Like

thank you****************************