#19 Python Tutorial for Beginners | If Elif Else Statement in Python

preview_player
Показать описание
Check out our courses:

Coupon: TELUSKO10 (10% Discount)

Coupon: TELUSKO10 (10% Discount)

Coupon: TELUSKO20 (20% Discount)

Udemy Courses:

For More Queries WhatsApp or Call on : +919008963671

In this lecture we will learn:
- Different units of a CPU
- Conditional statements in Python
- If and Else statements
- Execution of conditional blocks
- What is Indentation in Python?
- Nested if and else statements
- if, elif and else statements

#1
- CPU has three parts: CU (Control Unit), ALU ( Arithmetic Logic Unit) and MU ( Memory unit).
- MU is used to store variables and data.
- ALU has two parts:
1. AU - Arithmetic Unit ( it performs mathematical calculations)
2. LU - Logical Unit ( it makes a computer think something)

#2
If statement:-
- In programming, we have to apply conditions as per the logic of the code. In python, conditions can be applied through the if keyword.
- Use of the if keyword specifies the flow of execution of the code.
- Based on the condition of the problem statement, if keyword helps to decide which set of statements should be executed.
Syntax:-
if (condition):
statement;
- The statements of the if block will be executed only when the condition of the if statement is true. If the condition is false then it will skip the execution of statements present inside the if block.
- If consists of a block where you can write multiple statements. In python, it is also known as Suite.

#2
Indentation:-
- In Python, we have to follow certain indentations that specify the conditions that are present inside a certain block.
- Indentation simply means a certain number of spaces at the beginning of a code line.
- Indentation increases the readability of the code.

#3
Else block:-
- We can also use multiple if blocks in a code.
- Multiple uses of the if block decrease the efficiency of a code as the condition will be checked again and again in each if block.
- To make the code efficient, we use the else block.
- If the condition of the if block is true then the else block will be skipped. And if the condition of the if block is false then the else block will be checked and executed.

#4
Nested if and else statements:-
- Nested if and else statements are also allowed in Python.
- if statement can also be checked inside other if statement. This conditional statement is called a nested if statement.
- In nested, the inner if condition will be checked only if the outer if condition is true and that helps to see multiple conditions to be satisfied.
- Round brackets for putting a condition in the if statement is optional.

#5
if, elif and else statements:-
- elif stands for if-else.
- The if-elif statement is a shortcut of if..else chain.
- If the if condition s false, then the condition inside the elif will be checked and executed.
- While using if-elif statement at the end else block is added that will be executed when none of the above if-elif statements is true.

Editing Monitors :

More Learning :

Donation:
PayPal Id : navinreddy20
Рекомендации по теме
Комментарии
Автор

i'm 54 years old with no programming experience. I am constantly searching for good tutorials. This is by far the best python tutorial I have seen so far. Thanks. Keep up the good work.

knucklesandwich
Автор

(1).
a=int(input('enter any integer:'))
if a>0:
print('this is positive integer')
elif a<0:
print("this is negative integer")
else:
print('this is neither positive nor negative)

rohitchauhan
Автор

The best python teacher on the internet, NO DEBATE!!
I said it!!! Thank you so much Navin sir for taking your time and contributing to the python community with such a mindblowing course.... Hatts off to you

manavsingla
Автор

Thanks !
The new technique which I described here :

t, u, v = int(input("Number 1 : ")), int(input("Number 2 : ")), int(input("Number 3 : "))
print("The maximum value is : ", max(t, u, v))

dhruvsharma
Автор

a= float(input("enter the value"))
if a>0:
print("+ve")
elif a<0:
print("-ve")
else:
print("given no. is zero")

b=int(input("enter the first no."))
c=int(input("enter the sec no."))
d=int(input("enter the third no."))

if b>c and b>d:
print("b is greatest")
elif c>b and c>d:
print("c is greatest")
else:
print("d is greatest")

nigampratap
Автор

x=int(input('enter the first number '))
y=int(input('enter the second number '))
z=int(input('enter the third number '))
if x>y and x>z:
print('X is the largest')
elif y>x and y>z:
print('Y is the largest')
else:
print('Z is the largest')

rachitkumar
Автор

I have done your given assignments with best of my understanding. So they're:
1)
number=
if number>0:
print("Positive")

elif number<0:
print("Negative")
else:
print("Error")


2)
print('first number')
x=int(input())
print('second number')
y=int(input())
print('third number')
z=int(input())
if x>y and x>z:
print(x)
elif y>z and y>x:
print(y)
elif z>y and z>x:
print(z)
else:
print('none')

Thank you for your classes.

syedamirali
Автор

2nd Answer:

n1 = int(input("Enter 1st number: "))
n2 = int(input("Enter 2nd number: "))
n3 = int(input("Enter 3rd number: "))

if n1 > n2 and n2 > n3:
print (n1, "is the highest number among the three")

elif n1 < n2 and n2 < n3:
print (n3, "is the highest number among the three")

elif n1 < n2 and n2 > n3:
print (n2, "is the highest number among the three")

else:
print("Enter 3 different numbers")

qsuccess
Автор

I have purchased many python courses from different sites but i m learning from him haha... great guy :)

vikasgarg
Автор

At this point i realised i've never binged watch a tutorial for so long but it is this channel at which i've almost completed watching 3/4 of the python tutoring in 2 days! . You are a great teacher i must say. Your efforts are commendable. Thankyou so much . 😇😇☺️

tejaswibhargava
Автор

Nuvvu keka anna... Feeling proud of you... Just yesterday I started ur tutorials.... "Teluskuntune" unna eppati varaku... Not at all boring... I am more addicted to ur videos than any webseries(money heist, game of thrones)

sudheerreddy
Автор

I guess this was the correct solution according to the lesson for question 2:

x=int(input('Enter the first number: '))
y=int(input('Enter the second number: '))
z=int(input('Enter the third number: '))
if x>y and x>z:
print('X is the largest with value: ', x)
elif y>x and y>z:
print('Y is the largest with value: ', y)
elif z>x and z>y:
print('Z is the largest no with value: ', z)
else:
print('there are two or more equal nos.')

josephnduati
Автор

Q1: First question
num = int(input("Enter Number: "))
if num > 0:
print("positive")
elif num < 0:
print("Negative")
else:
print("Zero")


Q2: Second question
print("You are to insert 3 numbers:")
a = int(input("Enter First Number: "))
b = int(input("Enter Second Number: "))
c = int(input("Enter Third Number: "))
x = [a, b, c]
print(max(x))

jabuto-farmnigeria
Автор

Really awesome class sir. I'm addicted to your teaching

bharathreddy
Автор

x = input("enter the 1st number ")
y = input("enter the 2nd number ")
z = input("enter the 3rd number ")
if x>y and x>z:
print( x +" is the greatest number")
elif y>x and y>z:
print( y +" is the greatest number")
else:
print( z +" is the greatest number")

harshanasemasinghe
Автор

Sir your lectures are so interactieve and explanations are awesome, I have a suggestion please give us atleast 5 questions(for easy) and 3 questions(for medium) and 2 questions(for hard) because as you know ”practice makes man perfect 😊”

just_a_living_being
Автор

x=-7
if x>0:
print("positive number:")
elif x==0:
print("its zero")

else:
print("negative number")

print("its done")

divyag
Автор

Bacame a Python lover in 2 hours. You have amazing teaching skills and it must be appreciated. Thankyou so much.

moumitasaha
Автор

I am in love with programming just because of you sir.
Thank you for your strong support

bishwanathpandey
Автор

1.
x=int(input("Enter the value:"))
if x<0:
print("The no. is negative")
else:
print("The no. is positive")
2.
x, y, z=23, 16, 8
if (x>y) and (x>z):
print("X is Biggest")
elif(y>z):
print("Y is Biggest")
else:
print("Z is Biggest")

gayathribabu