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
# heads and tails game
heads = 1
tails = 2
bet = random.randint(heads, tails)

def coin_flip(bet_money,call):
  if bet == call:
    return bet_money
    return -bet_money
#money += coin_flip(10,heads)
#Call your game of chance functions here
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
    return -bet
#money += cho_ban("even",20)


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
    return 0
#money += card_game("10","15")

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
    return -r_num

Traceback (most recent call last):
File “”, line 49, in
File “”, 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


return 0-p1_bet

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


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

1 Like

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