Description

Links

Support my work: https://buymeacoffee.com/svit

Attribution

Illustrations by Story set

<a href="[<https://storyset.com>](<https://storyset.com/education>)">Illustrations by Storyset</a>

Hook

Conditional Statements Linear 1080.mp4

Up to this point we’ve executed all our commands one after the other, like reading a book from start to finish. But there are times (almost all the times) when we want the program to behave differently. Sometimes, we only want certain parts of the code to run if specific conditions are met, and other times we want to repeat a piece of code several times. Today we will learn about how we can control flow of the program in Python.

Input data

Before we start, let’s summarize the entire idea of programming with one simple chart:

flow.png

So far, we’ve been working with just the program and the output — writing code that prints results. But real programs often need to interact with users and respond to their input.

That brings us to the next key concept: how to get input from a user.


The input() function

Python provides a built-in function called input() to collect input from the user during program execution.

Whenever input() is called, Python pauses and waits for the user to type something and hit the Enter key.