5.2 16 Discovery

Hello there, I didn’t understand how to return a value in this program.

total_students = int(input(“How many students are in the class?”))
passing_students = int(input(“How many students passed this test?”))

def find_percentage():

percentage = int(find_percentage(25) * 100)
print("The percentage of students who passed is " + str(percentage) + “%”)

Didn’t understand where to fill in the “find_percentage” and I do not understand how to answer the last fill in the blank in this module.

Do you know the math-- what you divide by what to get the percentage? ie, if there are 10 total students, and 7 pass, then there is a .70 percent passing number. So. . . what do you divide by what to get that kind of figure?

Hello thank you for responding so quickly. Yes I know the math. I do not know where to plug the numbers in the code or what to ask the code to return.

Thank you

Well, you need to set a variable for the quotient between those two numbers-- and I am guessing, since you want the function to tell you the percentage, then that percentage value is what you want to “return”-- correct?

Good evening,yes, the percentage is what I want to return. The variables are confusing me a bit.

Are the following variables correct?

def find_percentage(passing_students / total_students) * 100:

return("passing_students / total_students * 100)

Thank you!


A clearer way to code that might be to set the results of your equation as a variable, ie “percentage = (passing students/total students) * 100”, and then to return the variable. Another issue is that, on the line that you define your function, you want to pass in the variables, not to set up your equation. That should be for a following line.

Thank you so much!!! That helped tremendously. I was able to figure out the code and correctly answer the last fill in the blank question in module 5.

You ROCK!!

Thank you!

Stay tuned I may need you again.

Hello all,
I have been doing the same as the above and it is not working for me. I have used parentheses and quotations and I just do not have the correct syntax. Can you please clarify? Thanks

Here are some samples of my mistakes:
percentage = passing_students/total_students * 100
percentage = (passing_students/total_students) * 100
“percentage = passing_students/total_students * 100”
percentage = (“passing_students/total_students * 100”)

The second try should not have yielded an error, as far as I can tell. Is the syntax error somewhere else in the code?

What error are you getting?

I concur that the second line of syntax should not cause a problem unless there is some other problem with your function header or definition. Can you share a little more about the problem you’re having?

1 Like


I don’t know if I did the screenshot right, but there it is. I am just filling in the box. It only says wrong. I typed the exact thing that is in my code that works.

So the wording in the question is tricky. They are not asking to calculate the percentage in the return statement. It is asking what variable divided by another variable could be used in the function body to HELP you determine the percentage?

Hint: you got it, there’s just some extra stuff that doesn’t need to be there.

I was having the same problem and getting this question wrong. Thanks a lot for help. I got the correct answer

1 Like

Good Evening,
I am stuck on the same problem, any assistance would be appreciated.

i need help for this too