Games of Chance problems, won't run unless there's an error?

Hi all,

https://www.codecademy.com/practice/projects/games-of-chance

I’m working through the heads or tails portion of the Games of Chance, but having some trouble getting it working. I’m using Atom text editor and running the code through Powershell. When I have an error, running the code will show that, but otherwise nothing comes up and the command line just stays at the path it was at when I tried to run it. Same thing happens when I run the code within Codecademy. Here’s what I’m running:

import random

money = 100

#Write your game of chance functions here
def coinflip(call, flip, bet):
    call = input("Heads or Tails? Enter your guess")
    flip = ['Heads', 'Tails']
    result = random.choice(flip)
    bet = input(f"How much do you want to bet? Enter amount between 0 and {money}")
    
    if  call == result:
        Print(f"""
        Result: {result}. You win!
        Money won: {bet}
        """)
    else:
        Print(f"""
        Result: {result}. Sorry, you lost!
        Money lost: {bet}
        """)

print(coinflip)

Where is the call to coinflip()?

Also, you didn’t define Heads, and you didn’t define Tails. Did you intend for those to be “Heads” and “Tails”? Then you have a list of strings that random.choice() can choose from.

2 Likes

Check this FAQ for a description of formatting code :+1:.

1 Like

Hi Harrjt,

Yes I did intend for those to be strings. I’ve fixed that and called the function as - print(coinflip) but I’m only getting this output:

image

Thanks so much, updated the post with correct formatting :slight_smile:

1 Like

Calling a function requires the function name followed by (). If there are arguments, they must be passed as well.

def test(a_str):
    return a_str + "!"


print(test)  # prints the representation of the function object
print(test())  # ERROR: would print the return of function test, **but** it's missing an positonal argument
print(test("This string"))  # would behave as expected