Python3 Function Question

Why does my answer also print NONE???

Write your win_percentage function here:

def win_percentage(wins, losses):
num_of_games = wins + losses;
precentage_of_wins = (wins/num_of_games)*100;
print(“The team won “+str(precentage_of_wins)+”% “+” of thier games”);
precentage_of_losses = (losses/num_of_games)*100;
print(“The team lost “+str(precentage_of_losses)+”% “+” of thier games”);

Uncomment these function calls to test your win_percentage function:

print(win_percentage(5, 5))

should print 50

print(win_percentage(10, 0))

should print 100

when you call your win_percentage function, you also want to print the returned result. But your function doesn’t return anything, so you get None (the absence of a return value)

2 Likes

If I add return 0 the function is going to return zero when I call it how do I make it return the result of what I input into my call statement.

At present you have two sets of print calls on the go so you’re getting more output than you expect, a simplified example of this is as below-

def print_this(this):
    print(this)

print(print_this("red"))
Out: "red"  # printed from inside function
Out: None  # printed the return from calling the function

It would make sense to either return a useful name and print that or to print within the function. An example of these two routes-

# method1
def return_this(this):
    return(this)  # return a specific name

print(return_this("red"))  # print the returned name
Out: "red"


# method2
def print_this(this):
    print(this)  # print a specific name

print_this("red")  # no print call
Out: "red"