Lec - 22: if, if else, if elif else in Python | Live Class with Student | Python for Tutorials |

Publicado em: 14 Maio 2024
no canal de: Intelligent Institute of Education
66
8

Lecture by Dr. (Prof.) Mohammad Fahim Akhtar
Text for join the course: C, C++, OOPs, Python & AI.
Contact: +971 5420 2425 6 (UAE), +91 860 346 2019 (India)

I'm uploading each lecture video with an example and executing programmes in Jupiter Notebook to help you understand it. You should also understand programming concepts. Shorter videos are easier to watch and understand, so practice often. If you have not yet subscribed, please do so and leave a comment because I want to improve education for all students, especially those who are economically weak.
In addition, I have included a detailed explanation here.

Topics covered in this session:
Conditional Statements:

1. if statement()
2. if…else statement()
3. if...elif...else statement()
4. nested if…elif …else statement()

Decision making is the most important aspect of almost every programming language.
As the name implies, decision making allows us to execute a specific block of code in order to make a specific decision.
Decisions are made based on the validity of specific conditions.

Python's decision-making statements are as follows.
Statement Description
If Statement The if statement is used to test a specific condition. If the condition is true, a block of code (if-block) will be executed.
If - else Statement The if-else statement is similar to if statement except the fact that, it also provides the block of the code for the false case of the condition to be checked. If the condition provided in the if statement is false, then the else statement will be executed.
Nested if Statement Nested if statements enable us to use if ? else statement inside an outer if statement.

Indentation in Python
Python does not allow the use of brackets for block level code in order to improve programming efficiency and simplicity.
In Python, indentation is used to declare blocks. If two statements have the same indentation level, they are part of the same block.
Generally, four spaces are used to indent the statements, which is the standard amount of indentation in Python.
Indentation is the most commonly used feature of the Python language because it declares a block of code.
All statements in a single block are intended to have the same level indentation.
We'll look at how indentation works in Python when making decisions and doing other things.

1. if statement
The if statement tests a specific condition and, if true, executes a block of code known as the if-block.
The condition of an if statement can be any valid logical expression that returns true or false.
The syntax of the if-statement is given below.
if expression:
statement

You can practice the following programs:
1. Write a Python program to find those numbers which are divisible by 7
and multiples of 5, between 1500 and 2700 (both included).

2. Write a Python program to guess a number between 1 and 9.

3. Write a Python program to construct the following pattern, using a
nested for loop.


*
* *
* * *
* * * *
* * *
* *
*
*
4. Write a Python program that accepts a word from the user and reverses it.

5. Write a Python program to count the number of even and odd numbers
in a series of numbers
Sample numbers : numbers = (1, 2, 3, 4, 5, 6, 7, 8, 9)
Expected Output :
Number of even numbers : 5
Number of odd numbers : 4

6. Write a Python program that prints each item and its corresponding type from the following list.
Sample List : datalist = [1452, 11.23, 1+2j, True, 'w3resource', (0, -1), [5, 12], {"class":'V', "section":'A'}]

7. Write a Python program to get the Fibonacci series between 0 and 50.
Note : The Fibonacci Sequence is the series of numbers :
0, 1, 1, 2, 3, 5, 8, 13, 21, ....

8. Write a Python program that iterates the integers from 1 to 50. For multiples of three print "Fizz" instead of the number and for multiples of five print "Buzz". For numbers that are multiples of three and five, print "FizzBuzz".
Sample Output :
fizzbuzz
1
2
fizz
4
buzz

9. Write a Python program that accepts a sequence of lines (blank line to
terminate) as input and prints the lines as output
(all characters in lower case).

10. Write a Python program that accepts a sequence of comma separated
4 digit binary numbers as its input. The program will print the numbers
that are divisible by 5 in a comma separated sequence.
Sample Data : 0100,0011,1010,1001,1100,1001
Expected Output : 1010

You can catch me on:
Facebook:
https://www.facebook.com/profile.php?...

Instagram:
  / intelligent_education_coaching  

Watch complete videos on:
   / @intelligentinstituteeducation  

Email:
the.intelligent.education@gmail.com


Nesta página do site você pode assistir ao vídeo on-line Lec - 22: if, if else, if elif else in Python | Live Class with Student | Python for Tutorials | duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Intelligent Institute of Education 14 Maio 2024, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 66 vezes e gostou 8 espectadores. Boa visualização!