Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

You must login to ask a question.

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Quizzma Latest Articles

4.5.4 Correct Portion CodeHS Answers

We thoroughly check each answer to a question to provide you with the most correct answers. Found a mistake? Tell us about it through the REPORT button at the bottom of the page. Ctrl+F (Cmd+F) will help you a lot when searching through such a large set of questions.

The most common answer is:

Amount of food and number of people
tons_of_food = 0.07
num_people = 25
Determine how much food each person gets
tons_of_food_per_person = tons_of_food / num_people
print tons_of_food_per_person
Ask the user how much food they took
tons_taken = float(input(“How many tons of food did you take? “))
round(tons_of_food_per_person, 5)
round(tons_taken, 5)
if tons_taken == tons_of_food_per_person:
print “Good job, you took the right amount of food!”
else:
print “You took the wrong amount of food!”

To ensure the program runs correctly in Python, especially in Python 3, you need to add parentheses around the arguments to the print function and ensure that the round function’s result is used in the comparison.

Here’s the corrected version of the code:

# Amount of food and number of people
tons_of_food = 0.07
num_people = 25

# Determine how much food each person gets
tons_of_food_per_person = tons_of_food / num_people
print(tons_of_food_per_person)

# Ask the user how much food they took
tons_taken = float(input("How many tons of food did you take? "))

# Round the values for comparison
rounded_tons_of_food_per_person = round(tons_of_food_per_person, 5)
rounded_tons_taken = round(tons_taken, 5)

# Compare and print the result
if rounded_tons_taken == rounded_tons_of_food_per_person:
    print("Good job, you took the right amount of food!")
else:
    print("You took the wrong amount of food!")

This corrected code includes the following adjustments:

  • Using parentheses with the print function, as required by Python 3 syntax.
  • Storing the results of the round function into variables for comparison. This ensures that when comparing tons_taken with tons_of_food_per_person, both numbers are rounded to the same number of decimal places, making the comparison accurate.
  • Asking the user for their input on how much food they took, rounding that input, and then comparing it to the rounded amount of food per person to determine if they took the correct amount.

Was this helpful?




Quizzma Team

Quizzma Team

The Quizzma Team is a collective of experienced educators, subject matter experts, and content developers dedicated to providing accurate and high-quality educational resources. With a diverse range of expertise across various subjects, the team collaboratively reviews, creates, and publishes content to aid in learning and self-assessment.
Each piece of content undergoes a rigorous review process to ensure accuracy, relevance, and clarity. The Quizzma Team is committed to fostering a conducive learning environment for individuals and continually strives to provide reliable and valuable educational resources on a wide array of topics. Through collaborative effort and a shared passion for education, the Quizzma Team aims to contribute positively to the broader learning community.

Related Posts

Leave a comment