Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.


+11 votes

elif weight <= "10":

  return "light"

elif weight <= "69":

  return "heavy"

elif weight >= "70":

  return "very heavy"

When I enter 5 for the weight it returns back heavy. Can someone explain why it is doing this

asked in CSC201 Spring 2021 by (1 point)

More context please... which problem are you working on? Also, maybe show us more of your code? Since this isn't an assignment, you can post the full code.

Use the {} button to format it as code.

3 Answers

+4 votes

That is because your code that is supposed to return heavy is supposed to be "10" <= weight <= "69". Your code right now is weight <= "69" which means it will also include weight <= "10" because that is also less than 69lbs.

answered by (1 point)
sample quiz question 29
+4 votes

First it checks if 5 <= 10, which it is, so now weight is 'light'. The problem is that after checking that, it checks if 5 <= 69, which is also correct, and weight gets changed to 'heavy'. To fix this you would want to change the second elif to check for 10 < weight <= 69.

answered by (1 point)
+1 vote

Your weight to return heavy should be between 11-69, not just less than 69.

answered by (1 point)