The if-elif-else Statement in Python

The if-elif-else Statement in Python

Neso Academy

1 год назад

49,219 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@daregamerboy2255
@daregamerboy2255 - 05.09.2023 19:30

Thank u for your effort sir 🙏

Ответить
@shivamchakrawarti8262
@shivamchakrawarti8262 - 05.09.2023 19:44

Great lecture sir if it is possible then please upload these lectures per day so that we remain consistent..

Ответить
@kristinamwangekan2471
@kristinamwangekan2471 - 05.09.2023 19:53

Thank you...well explained

Ответить
@zaki695
@zaki695 - 05.09.2023 20:24

Thank you sir

Ответить
@studentgroup1017
@studentgroup1017 - 05.09.2023 21:02

Thank you for Amazing Python course,
Tottle how many videos are there of this course. Please replay

Ответить
@jatin607
@jatin607 - 05.09.2023 23:20

Sir why are you left the Java playlist incomplete. Sir you are making so much efforts to make the video and we students are also look for the content which is completed.kindly upload the remaining video of Java playlist

Ответить
@SushilaMeena-1804
@SushilaMeena-1804 - 06.09.2023 14:53

Today's i perform this code in my lab but I can't understand but now my concept clear😊😊

Ответить
@leealvin7671
@leealvin7671 - 06.09.2023 15:39

Let’s take n = 6

n = 6
if n % 2 == 0:
print(“Number is divisible by 2”)
elif n % 3 == 0:
print(“Number is divisible by 3”)
else:
print(“Number is neither divisible by 2 nor 3”)
print(“Done!”)

The output will be:
Number is divisible by 2
Done!

Why is it though, even though 6 can also be divisible by 3

Reason: Since the first condition is satisfied, Python interpreter wouldn’t consider the second condition onwards and will continue after exiting the if-elif-else statement.

Improvement:

n = 6
if n % 2 == 0 & n % 3 == 0:
print(“Number is divisible by 2 and 3”)
elif n % 2 == 0:
print(“Number is divisible by 2”)
elif n % 3 == 0:
print(“Number is divisible by 3”)
else:
print(“Number is neither divisible by 2 nor 3”)
print(“Done!”)

By adding a line of code, you may get the desired output

Output:
Number is divisible by 2 and 3
Done!

Ответить
@GousyaShaik-bq3xy
@GousyaShaik-bq3xy - 06.09.2023 16:45

Happy teacher's day sir😅

Ответить
@DEWAAN-ud7ss
@DEWAAN-ud7ss - 06.11.2023 06:46

Thank you sir

Ответить
@RealRadaiZabala
@RealRadaiZabala - 16.12.2023 20:37

You are a great teacher, thank you very much... @Neso Academy

Ответить
@TheZentleMan
@TheZentleMan - 13.02.2024 11:03

Must run it 😂😅



print("Do you want to know what you were in a past life?")

while True:
a=input("enter 'yes' or 'no' to continue :")
if a=="yes":
print("\n Chutiya thhe tum!")
break
elif a=="no":
print("\n toh bhaad mein jao phir! ")
break
else:
print("\n PLEASE ENTER ONLY 'yes' or 'no' \n")

Ответить
@chandraj1053
@chandraj1053 - 16.02.2024 18:09

Good explanation sir

Ответить
@GitaAska-is6yz
@GitaAska-is6yz - 26.04.2024 14:19

Tutorial python tricks and modifications

Ответить
@MaTHNERVEs
@MaTHNERVEs - 03.05.2024 16:55

How can i get pdf of class. I need this. My exam is knocking doors

Ответить
@kajalHere-r1d
@kajalHere-r1d - 23.07.2024 20:20

thankyou for this ...

Ответить
@lawrenceoko1783
@lawrenceoko1783 - 27.07.2024 02:42

Great

Ответить
@PacifistNihilist
@PacifistNihilist - 31.08.2024 22:26

Thank you for the explanation. Also thank you for explaining what WAP meant because I had something totally different in mind 😂

Ответить
@IamGay-xi9ny
@IamGay-xi9ny - 02.10.2024 09:28

the div by 3 should be done by a loop

Ответить
@adikwusunday3907
@adikwusunday3907 - 02.10.2024 21:39

Very well lecture.

Ответить
@Freefireboy-j4x
@Freefireboy-j4x - 16.10.2024 17:16

I am in 8th grade and tomorrow is my practical test of computer.....You helped me so much 🙏

Ответить
@alexjrmatta
@alexjrmatta - 24.10.2024 07:03

Excelente video !❤❤🎉🎉

Ответить
@hadi1725
@hadi1725 - 26.11.2024 16:14

thank u for ur hard work

Ответить
@DeathDishonor-i9k
@DeathDishonor-i9k - 24.12.2024 03:43

thanks a lot

Ответить
@My-tiny-worldd
@My-tiny-worldd - 14.03.2025 08:00

what a excellent explanation!!ty!!

Ответить