From the course: Programming Foundations: Real-World Examples

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Switch and case statements

Switch and case statements - Python Tutorial

From the course: Programming Foundations: Real-World Examples

Start my 1-month free trial

Switch and case statements

- In addition to the inclusive vegan pizza, I'm also going to order a pizza for myself. The pizza company offers a different pizza deal every day of the week, so I'll make my choice based on the daily special. In this scenario, I need to make a decision based on a single value, the day of the week. One way I can evaluate this series of options is as an if-else-if chain that says if today is Sunday, then order the spinach pizza. Else, if today is Monday, order the mushroom pizza. Else, so today is Tuesday, order the pepperoni pizza and so on. When my program goes to evaluate the if-else-if chain, it'll evaluate each of those expressions in order. So, let's do that now to pick a pizza. I'll start at the top of the list and work my way down. Is it Sunday? No. Is it Monday? No. Is it Tuesday? No. Is it Wednesday? No. Is it Thursday? No. Is it Friday? No. Is it Saturday? Yes! Today is Saturday, Hawaiian pizza, one of my favorites. - You know today is Saturday and it's at the bottom of the…

Contents