+ 2
What's wrong with my code?
When you run the code it doesn't do the math. My code is in the comment section
6 Answers
+ 4
Now cover all your code and look at the first 4 lines only. You have got a function there. But what is male and female? They are not meaningful names inside this function. This is called local scope. To make it work, male and female should be arguments:
def breed(male, female):
And in the last line where you invoke the function, you need to pass the actual values that were provided as input.
print(breed(male, female))
There are also other mistakes, but it would be easier if you gave a link to your code, so people can fix it more easily.
+ 2
You may share your code? without knowing what you tried we cannot help you
+ 1
Can you share your code, so that we can help you better.
+ 1
Clyde Jhan Paglinawan
your function does not accept parameters. Using globals is not advisable. I have it working, but I think you might have a logic error. would 1 female and 2 males produce the same result as 2 females and 1 male?
def breed(m, f):
parents = m + f
mate = parents * 2
return mate
for_cats = print('Input the number of your cats: ')
cats = int(input())
input_c = (f"(for_cats){cats}")
if cats > 0:
print("How many are males?: ")
male = int(input())
print("How many are females?: ")
female = int(input())
if (male >= 1) and (female >= 1):
print(breed(male,female))
0
def breed():
parents = male + female
mate = parents * 2
return mate
for_cats = print('Input the number of your cats: ')
cats = int(input())
input_c = (f"(for_cats){cats}")
if cats > 0:
print(f"How many are males?: ")
male = int(input())
print(f"How many are females?: ")
female = int(input())
if (male > 1) and (female > 1):
print(breed)
0
Clyde Jhan Paglinawan
Also, the total is not crosschecked.