Trouble with my coin_flip() function

I’m officially stumped,
I’ve tried everything in the book to get this code to work and I’m officially at deads end. The code skips right over my coin_flip() function and doesnt perform any of the if statements I’ve written. I know its something small but I’m officially through trying to figure this out.

Please Help!!!

somebody help me please!

import random

money = 100

name = input("Please Enter a Username: ")
print('\n')
print("Hello: " + name)
print("Welcome to Coin Toss Pro!")
print("Available cash winnings: " + "$", money)
print('\n')

# Write your game of chance functions here


def coin_flip(guess, amount):
    winner = random.randint(1, 2)
    bet = input("Please enter heads or tails: ")
    wager = input("Please Enter Your Wager: ")
    print("You Wagered: " + "$", wager, " on: ", bet)
    print('\n')
    # conditional logic
    if guess == "heads" and winner == 1:
        cash_total = money + amount
        print("Winner: Heads! Your Cash Total: ", cash_total)
        #return cash_total
    if guess == "heads" and winner == 1:
        cash_total = money + amount
        print("Winner: Heads! Your Cash Total: ", cash_total)
        #return cash_total
    if guess == "tails" and winner == 2:
        cash_total = money + amount
        print("Winner: Heads! " + "Your Total: ", cash_total)
        #return cash_total
    if guess == "tails" and winner == 2:
        cash_total = money + amount
        print("Winner: Heads! " + "Your Total: ", cash_total)
        #return cash_total
    else:
        cash_total = money - amount
        print("You Lost!")
        print("cash total: ", cash_total)
        #return cash_total
        #replay = input("Play Again (y/n): ")


# Call your game of chance functions here
    coin_flip("bet", wager)

Thanks in advance

You have a few issues. First you need to out-dent your function call at the end of your code.
The way you have it set up, there is no need to pass arguments to the function, nor does the function need to accept parameters. You query the user for those values inside the function itself. You would then need to change guess to bet in all of your if statements. Hope this helps!

2 Likes

I got this to work just a little bit ago but I’m gonna try your method out as well.

import random

money = 100

name = input("Please Enter a Username: ")
print('\n')
print("Hello: " + name)
print("Welcome to Coin Toss Pro!")
print("Available cash winnings: " + "$", money)
print('\n')
bet = input("Please enter heads or tails: ")
wager = input("Please Enter Your Wager: ")
int_wager = int(wager)


# Write your game of chance functions here
def coin_flip(guess, amount):
    print("You Wagered: " + "$", int_wager, " on: ", bet)
    print('\n')
    winner = random.randint(1, 2)
    # conditional logic
    if guess == "heads" and winner == 1:
        cash_total = money + amount
        print("Winner: Heads! Your Cash Total: ", cash_total)
        return cash_total
    if guess == "tails" and winner == 2:
        cash_total = money + amount
        print("Winner: Tails! " + "Your Total: ", cash_total)
        return cash_total
    else:
        cash_total = money - amount
        print("You Lost!")
        print("cash total: ", cash_total)
        return cash_total


# Call your game of chance functions here
coin_flip(bet, int_wager)

If it’s working like this, I’d leave it. :+1:

I just ran your updated code, and it seems to work as expected. One suggestion you may consider is changing this line of code:

wager = input("Please Enter Your Wager: ")

to this:

wager = int(input("Please Enter Your Wager: "))

Then you would no longer need to convert wager to int_wager. It would be one less variable. It’s entirely up to you. Happy Coding!

@geekmonster.jt, @midlindner
Does the CA interface let you use input()? I always get EOFError: EOF when reading a line when I do so, at least in this particular project.

Trying it out now

Thanks!!!

Had the same problem so I just did mine in PyCharm. Must be a reason why they wanted Anaconda in the mix.

1 Like

I haven’t started any of the CC Python courses, but I have noticed in other courses that not all methods are available at every level, so I’m not surprised that’s the case.