Skip to Main Content
Python for Kids, 2nd Edition
book

Python for Kids, 2nd Edition

by Jason R. Briggs
November 2022
Beginner content levelBeginner
368 pages
6h 47m
English
No Starch Press
Content preview from Python for Kids, 2nd Edition

5Asking Questions with if and else

Image

In programming, we often ask yes or no questions, and do something based on the answer. For example, we might ask, “Are you older than 20?” and, if the answer is yes, respond with “You are too old!” These sorts of questions are called conditions, and we combine conditions and their responses into if statements. Conditions can be more complicated than a single question, and if statements can be combined with multiple questions and different responses based on the answer to each question. In this chapter, you’ll learn to use if statements to build programs.

If Statements

We might write an if statement in Python ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python Cookbook, 3rd Edition

Python Cookbook, 3rd Edition

David Beazley, Brian K. Jones
High Performance Python, 2nd Edition

High Performance Python, 2nd Edition

Micha Gorelick, Ian Ozsvald

Publisher Resources

ISBN: 9781098141400