Learn

Although it was interesting and fun, Kenny didn’t feel that the farm life was quite right for him. But his time on the farm made him interested in food and food safety, so Kenny became a health inspector.

In his job as a health inspector, he had to give the restaurants he inspected a grade. In order to grade them fairly, Kenny knew he had to develop a system to decide their score based on a set of conditions of the restaurant.

Kenny would check each area in the restaurant in sequence: first the dining room, then the bar, then the servers station, and finally the kitchen.

If he found any pests, dirt, or something unsanitary at any of those locations he would subtract a letter from the overall grade of the restaurant. The restaurants always started with an A, but by the end of the inspection sometimes they ended up having an F, and no one wants to eat at a restaurant with an F health grade.

Kenny knew that what he had developed was a control flow. He had a set sequence he followed, and throughout that sequence, based on some conditionals he would lower the health grade of the establishment. This is a way of thinking that he learned when developing software. Kenny had turned his job as a health inspector into a sequence of if/then statements within a control flow. This allowed him to grade each restaurant fairly and consistently.

Instructions

1.

In the code editor, you’ll find a short text-based adventure game where you can play as health inspector Kenny and give your daily quota of restaurants their health grades.

Click run, then copy and paste python kenny_the_health_inspector.py into the terminal on the far right titled bash and hit return or enter on your keyboard.

Games like this, and in fact most functions and programs, rely heavily on control flow to guide the user through the application. Take a look at the code for the game itself and see if you can see examples of control flow logic.

Anywhere you see if statements, or comparative operators like ==, >=, >, or <, there’s logic at work!

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.
Already have an account?