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.

Categories

+9 votes

I used this code
def analyzeWeight(weight):

if weight == "-1":
    return "Thanks for using weight analyzer"
elif weight < "2":
    return "very light"
elif "2" <= weight <= "10":
    return "light"
elif "10" <= weight <= "69":
    return "heavy"
elif weight >= "70":
    return "very heavy"

and it still printed heavy. Do you have any other suggestions

related to an answer for: sample midterm 2
asked in CSC201 Spring 2021 by (1 point)

1 Answer

+3 votes

There are three problems with this-
1. the def analyzeWeight function shouldn't return anything, it should print the values. Also you asked the user to enter strings, the numbers do not need quotations usually.
2. the -1 you have in the weight is like an endpoint. It should be under a while loop in your main function.
3. Your 2nd and 3rd elifs, both cases the weight can be equals to 10, python will get confused.

So it would something like this in your main,
1. prompt the user
2. Until the user enters -1, call the analyze function then prompt the user to enter the weight again. When you're calling to the function, it will check and print the appropriate statement.
3. print the last line where you thank the user outside the while loop...

answered by (1 point)
...