1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Python for Developers

Connected

Exercise

Conditional while loops

Your recipe scaler needs to verify that you have enough of each ingredient before scaling up the recipe. You'll use a while loop combined with conditional logic to check ingredient quantities and provide helpful status updates. You have a variable ingredients_checked that tracks how many ingredients you've verified, and total_ingredients representing the total number of ingredients in your tomato and basil pasta recipe.

Instructions

100 XP
  • Create a while loop that continues as long as ingredients_checked is less than total_ingredients.
  • Increase the ingredients_checked counter by 1 each time the loop runs.
  • Using conditional statements, check whether fewer than 4 ingredients have been reviewed.
  • If not, check whether 6 or fewer ingredients have been reviewed.