RUVIDEO
Поделитесь видео 🙏

3.Python Basics If then else and While Loops

Thanks for watching the video.

Also I would like to introduce you to our new course on udemy if interested. "Learn Python using Amazon SageMaker".Do try this URL: https://www.udemy.com/course/learn-python-using-amazon-sagemaker/?couponCode=583FD5DF08490CEEDFD0


Decision making is required when we want to execute a code only if a certain condition is satisfied.

The if…elif…else statement is used in Python for decision making.

The while loop in Python is used to iterate over a block of code as long as the test expression (condition) is true.

We generally use this loop when we don't know the number of times to iterate beforehand.

While writing code in any language, you will have to control the flow of your program. This is generally the case when there is decision making involved -
you will want to execute a certain line of codes if a condition is satisfied, and a different set of code incase it is not. In Python, you have the if,
elif and the else statements for this purpose. In this tutorial, you will work with an example to learn about the simple if statement and gradually move on to if-else and then the if-elif-else statements.
You will also learn about nesting and see an nested if example.
Lets get started....
1.Simple if statement
This is the simplest example of a conditional statement.
The syntax is:
if(condition):
indented Statement Block

The block of lines indented the same amount after the colon (:) will be executed whenever the condition is TRUE.

2.if-else Statement
The if-else statement is used to code the same way you would use it in the English language.
The syntax for the if-else statement is:
if(condition):
Indented statement block for when condition is TRUE
else:
Indented statement block for when condition is FALSE
3.Multiple tests: if-elif-else Statement
Lets break down the problem we have so far and try to frame it in words before we jump into code.

Step 1. Input the two scores: score_theory and score_practical

Step 2. Check that neither of the score exceed the maximum possible score that is 50.
This also solves the problem of the total score not excedding 10).
If either one is greater than 50 - display warning and exit.
2.1 Check for score_theory
2.2 Check for score_practical
Step 3. If neither exceeds the score, display a 'Score okay' and exit

The syntax followed by the if-else-if statement is:

if(Condition1):
Indented statement block for Condition1
elif(Condition2):
Indented statement block for Condition2
else:
Alternate statement block if all condition check above fails

while loop:
The while loop in Python is used to iterate over a block of code as long as the test expression (condition) is true.
We generally use this loop when we don't know the number of times to iterate beforehand.

What is while loop in Python?
The while loop in Python is used to iterate over a block of code as long as the test expression (condition) is true.

We generally use this loop when we don't know the number of times to iterate beforehand.

Syntax of while Loop in Python
while test_expression:
Body of while
In Python, the body of the while loop is determined through indentation.
The body starts with indentation and the first un indented line marks the end.

Python interprets any non-zero value as True. None and 0 are interpreted as False.
While loop with else
Same as with for loops, while loops can also have an optional else block.
The else part is executed if the condition in the while loop evaluates to False.
The while loop can be terminated with a break statement.
In such cases, the else part is ignored.
Hence, a while loop's else part runs if no break occurs and the condition is false.

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «3.Python Basics If then else and While Loops», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.