Control Flow in Python - If Elif Else Statements

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 พ.ย. 2018
  • Learn how to use if elif else statements in Python to control the flow of your programs.
    🔥Subscribe for more videos like this: goo.gl/6PYaGF
    🔥Python tutorial for beginners: • Python Tutorials for B...
    Python Exercises for Beginners:
    programmingwithmosh.com/pytho...
    Python Cheat Sheet:
    programmingwithmosh.com/pytho...
    Want to learn more from me? Check out my blog and courses:
    programmingwithmosh.com
    / programmingwithmosh
    / moshhamedani

ความคิดเห็น • 164

  • @victorjo7918
    @victorjo7918 ปีที่แล้ว +32

    Finally somebody talks about indenting,every detail counts.Very nice tutorial with a bonus quiz at the end.

    • @YoTone21
      @YoTone21 10 หลายเดือนก่อน +1

      Exactly! I was struggling just now wondering what happened when my text mirrored the “correct answer” literally back spaced to indent my way vs coddys way and it worked

  • @azizt6773
    @azizt6773 2 ปีที่แล้ว +8

    Mosh, you are a legend im gonna enroll in your program in September this year. I'm happy that I've stumbled across you

  • @ziniazinia4707
    @ziniazinia4707 4 ปีที่แล้ว +97

    U have teached a 10000000000x greater than my teacher🤣🤣🤣🤣🤣

  • @RFUQUA26
    @RFUQUA26 11 หลายเดือนก่อน

    I came for if statements and learned a lot more, thanks for the video.

  • @tahaahmed627
    @tahaahmed627 4 ปีที่แล้ว +25

    Amazing tutorials . . . I am learning so much about python so easily!

    • @asshivam8117
      @asshivam8117 2 ปีที่แล้ว

      th-cam.com/video/zO9Z4inmLzM/w-d-xo.html
      Topic : Control Flow and User Input in Python
      Department : CSE
      By Aditya(IIT DELHI)
      Notes available in Description
      Like, Share and Comment on the video
      Subscribe to the Ninepointers TH-cam Channel

  • @Slopki16
    @Slopki16 2 ปีที่แล้ว

    Thank you sooooo much for this video!!!! Im making new project and i have to problems with if else and after looking 4 sec of your video i get it and fixed it.

  • @talinanderson611
    @talinanderson611 ปีที่แล้ว +3

    Thanks for your super informative tutorials! It really helps in my class. Mr.Hutter makes it too hard!

  • @Science-Made-Easy
    @Science-Made-Easy 2 ปีที่แล้ว +8

    Mosh has made my life easier, you are the world's no.1 programmer and you are an excellent teacher... Thank You Very Much @MoshHamedani

    • @asshivam8117
      @asshivam8117 2 ปีที่แล้ว

      th-cam.com/video/zO9Z4inmLzM/w-d-xo.html
      Topic : Control Flow and User Input in Python
      Department : CSE
      By Aditya(IIT DELHI)
      Notes available in Description
      Like, Share and Comment on the video
      Subscribe to the Ninepointers TH-cam Channel

  • @rbgpro4
    @rbgpro4 2 ปีที่แล้ว +9

    thank you so much for this you literally explained it way better than my teacher

  • @wisdomdavid4923
    @wisdomdavid4923 ปีที่แล้ว

    I love you mosh! Thank you ...all the way from Nigeria

  • @isabellawilliams52
    @isabellawilliams52 10 หลายเดือนก่อน

    Genuinely helpful with the indenting tip.

  • @ketexazeez1723
    @ketexazeez1723 2 ปีที่แล้ว

    Awesome 👌. You are a true educator

  • @isaacmatos2079
    @isaacmatos2079 ปีที่แล้ว

    You’re great bro, greetings from Dominican Republic

  • @sheikhmkrifat7749
    @sheikhmkrifat7749 2 ปีที่แล้ว +12

    I am not so good in English , in 15:38 can you tell me how "Bag"> "apple" . They both are string , and how can you define one string is greater than another one?
    Thank You

    • @wambuasammy9161
      @wambuasammy9161 2 ปีที่แล้ว +1

      yes...let him answer this one

    • @howpunny3570
      @howpunny3570 2 ปีที่แล้ว +8

      i think he means that because bag starts with b (second letter of the alphabet) and apple starts wtih a (first letter of the alphabet)
      and because b = 2nd it also equals 2, a = 1st it also equals 1, and 2 is more than 1, therefore bag is greater than apple?
      then since cat is greater than bag, cat = c = 3rd letter of the alphabet = 3 > bag = 2nd letter of the alphabet = 2

    • @sheikhmkrifat7749
      @sheikhmkrifat7749 2 ปีที่แล้ว

      @@howpunny3570 Thank you very much brother .

  • @Tanookiiii
    @Tanookiiii 2 ปีที่แล้ว +1

    THANK YOU FOR HELPING MY STRUGGLE

  • @nobelalan2728
    @nobelalan2728 4 ปีที่แล้ว +6

    Thank you very much for the simple illustration

  • @crstophermartinez8662
    @crstophermartinez8662 ปีที่แล้ว

    Thanks man for helping become a little more knowledgeable

  • @adeyinkaadekanmi6586
    @adeyinkaadekanmi6586 2 ปีที่แล้ว

    You are a good instructor

  • @BahoraAvazova
    @BahoraAvazova 5 หลายเดือนก่อน +1

    thank you bro for a great tutorial lesson

  • @leynahoang3141
    @leynahoang3141 2 ปีที่แล้ว +1

    you’re helping me with my comp sci midterm 😭😭

  • @sibongilemalama
    @sibongilemalama ปีที่แล้ว

    It has made me to understand python very well 🥳🥳

  • @w8448
    @w8448 5 หลายเดือนก่อน

    Thank you very much, you're a wonderful teacher.

  • @lasc1991
    @lasc1991 4 ปีที่แล้ว

    Hey Mosh, you are a good teacher !! Explain very well .

  • @StrigWilson
    @StrigWilson 3 ปีที่แล้ว +15

    I'm a total noob but I've always been into computers, covid put me out of a job so here I am!
    Thanks man i appreciate people like you helping me get certs, because school isn't an option for me financially

    • @rukuonomi
      @rukuonomi 2 ปีที่แล้ว

      got a job yet?

    • @StrigWilson
      @StrigWilson 2 ปีที่แล้ว +5

      @@rukuonomi just started a help desk position last month! Keep on the grind man

    • @asshivam8117
      @asshivam8117 2 ปีที่แล้ว

      th-cam.com/video/zO9Z4inmLzM/w-d-xo.html
      Topic : Control Flow and User Input in Python
      Department : CSE
      By Aditya(IIT DELHI)
      Notes available in Description
      Like, Share and Comment on the video
      Subscribe to the Ninepointers TH-cam Channel

  • @Inte8ranD
    @Inte8ranD 7 หลายเดือนก่อน

    Thanks, Mosh....@Programming with Mosh

  • @ChrisWales-j5u
    @ChrisWales-j5u 27 วันที่ผ่านมา

    Thank you so much for your lecture

  • @GreenlackX
    @GreenlackX 2 ปีที่แล้ว +1

    Thank you so much 😊

  • @imanibillahismail8526
    @imanibillahismail8526 ปีที่แล้ว

    Thank you Mosh👍

  • @TheMeditationHub2023
    @TheMeditationHub2023 ปีที่แล้ว

    You are the BEST!

  • @royaebadi-gi5gt
    @royaebadi-gi5gt 10 หลายเดือนก่อน +3

    your tutorials are comprehensive and straightforward so that beginners can grasp it easily.

  • @user-nb3ue4nh3t
    @user-nb3ue4nh3t 7 หลายเดือนก่อน

    Thanks 👍 you are a good teacher 😊

  • @shakeel0atmeal273
    @shakeel0atmeal273 ปีที่แล้ว

    Thank you my friend 🙏🙏🙏

  • @habiba-cz4mc
    @habiba-cz4mc 2 ปีที่แล้ว

    Your explanation is better than my TA

  • @Satyajit5858
    @Satyajit5858 3 ปีที่แล้ว

    Nice explaination sir

  • @ramlaaal
    @ramlaaal 3 ปีที่แล้ว

    sir what theme do you use in vs code

  • @marwanmarwan5810
    @marwanmarwan5810 4 ปีที่แล้ว +3

    Sir Mosh.... you are awsome !

  • @sanzay.
    @sanzay. 4 ปีที่แล้ว +1

    15:10 what did u mean by sorting in case of bag>apple and bag>cat? Didn't understand this part!

  • @hazemalawawdeh9318
    @hazemalawawdeh9318 4 ปีที่แล้ว

    You are a smart person boi

  • @julbeeyaren8483
    @julbeeyaren8483 10 หลายเดือนก่อน

    Mosh is my favourite Tutor so far. I panic if I can't find his video on a topic I want 🤣

  • @futurism010
    @futurism010 2 ปีที่แล้ว

    No any words to express for you @MoshHamedani🤭!

  • @todormetzov1235
    @todormetzov1235 ปีที่แล้ว

    thank you 🎉 ❤

  • @dailysiva2582
    @dailysiva2582 3 ปีที่แล้ว

    *Really awesome*

  • @osho2810
    @osho2810 3 ปีที่แล้ว

    Great Sir

  • @mcblackk_x5011
    @mcblackk_x5011 2 ปีที่แล้ว

    wow teachers on purpose dont teach this way cuz they don't care, great video!!!

  • @MuhammadAhmed-vi2xt
    @MuhammadAhmed-vi2xt 5 ปีที่แล้ว +3

    Sir Mosh please make course on Django 2.1.3 because you already maked course on python now please make on django and its my humble request to you.

  • @SeifCookz
    @SeifCookz 2 ปีที่แล้ว

    whats the app you used for this tutorial?

  • @alexanderhanks9051
    @alexanderhanks9051 ปีที่แล้ว

    Thanks

  • @killablaze1152
    @killablaze1152 3 ปีที่แล้ว +2

    Sir good day, My name is Jason and I need your help.
    I'm a beginner in python doing if, else statements now.
    Please tell me how can I get in contact with you directly.

  • @ItzTyrax
    @ItzTyrax ปีที่แล้ว

    is there a way to apply this to labels?
    Say I have a label with the variable name LED
    so
    LED = Label(0,200,200)
    then maybe check the VALUE like LED.value is above say 25
    It changes the position?

  • @rajabhishek2936
    @rajabhishek2936 5 ปีที่แล้ว +2

    Love it.....

    • @rajabhishek2936
      @rajabhishek2936 5 ปีที่แล้ว

      @@programmingwithmosh I complete core python sir.

  • @MzUrKeL
    @MzUrKeL 10 หลายเดือนก่อน

    This is possibly the best breakdown. I've seen so far!

  • @moondemudimba7920
    @moondemudimba7920 5 ปีที่แล้ว +2

    amazing tutorial

    • @moondemudimba7920
      @moondemudimba7920 5 ปีที่แล้ว +1

      I know Java, C, C++ and PHP I have been coding in those languages for 4 years now.. .. I want to extend my programming skills to solving problems, that's why I chose to learn python... I have been reading about it. It's an awesome and ever growing programming language... So it's worth learning...

  • @YoTone21
    @YoTone21 10 หลายเดือนก่อน

    You are the best thank you!! I was going over if else statements using coddy tech, and they failed to explain indentation is important. Literally as soon as I indented the damn code worked smh 😂😂

  • @toddmaek5436
    @toddmaek5436 ปีที่แล้ว

    So is it safe to say that when thinking of the operators to think of them as logic gates?

  • @tankionlinegamer126
    @tankionlinegamer126 2 ปีที่แล้ว

    Sir, do you have any Ebook for complete beginners, if you know best e book pls share

  • @mohammadanarul624
    @mohammadanarul624 5 ปีที่แล้ว +1

    thank you so much sir...

  • @HusamEmran
    @HusamEmran ปีที่แล้ว

    the last part of bag and apple i did not get it ? the rest was well explained thank you

  • @user-gj8yk4fx7o
    @user-gj8yk4fx7o 4 หลายเดือนก่อน +1

    It works good in Mac too right?

  • @prashh47
    @prashh47 ปีที่แล้ว

    Nice

  • @teluguhacker4160
    @teluguhacker4160 2 ปีที่แล้ว

    Thank you so much sir . Please sir make video easy words in English sir

  • @SureshKumar-gm9cz
    @SureshKumar-gm9cz 5 ปีที่แล้ว

    Pls add more videos

  • @BobWila
    @BobWila ปีที่แล้ว

    Hi Mosh, so say I got this condition where if he opts to select yes to retake the question, how can I rerun that specific variable/question?

    • @sammygang3181
      @sammygang3181 8 หลายเดือนก่อน

      Not sure but I think it's goto

  • @user-hd3zq6we8b
    @user-hd3zq6we8b 5 ปีที่แล้ว

    Best explanation 👍 sir

  • @roselynearroyocastillo8402
    @roselynearroyocastillo8402 3 ปีที่แล้ว

    im sorry that idk this but what is this used for?

  • @milankbudha
    @milankbudha 4 ปีที่แล้ว +1

    in this video,which python IDE you had used?plzz tell me

  • @hazemalawawdeh9318
    @hazemalawawdeh9318 4 ปีที่แล้ว

    Can you make a math QUIZ in python ?

  • @roqiyajaved6570
    @roqiyajaved6570 7 หลายเดือนก่อน

    How do you save to go to the next lin

  • @kripasaxena457
    @kripasaxena457 4 ปีที่แล้ว

    In last program ..I tried it but it gave me error as 'c' is not defined...reply soon

  • @nobelalan2728
    @nobelalan2728 4 ปีที่แล้ว +1

    but I have question about the age. I think it should be >=18 and not

    • @newshapeymani9119
      @newshapeymani9119 2 ปีที่แล้ว

      its because when you try to write it in the shorter version it reads like this 18

  • @himanshuthakur4761
    @himanshuthakur4761 9 หลายเดือนก่อน

    How is bag greater than apple(in what context)?

  • @ucancallmeultra.3864
    @ucancallmeultra.3864 2 ปีที่แล้ว

    I didnt quite understand how he said bag is greater than apple did he meant what words comes before in the dictionnary?

  • @PKOVBPK
    @PKOVBPK 6 หลายเดือนก่อน

    Hi Mosh I have one question and I can´t find answer. I read temperature which is float number. I have some zone from -10 to 10. And when I break this zone from outside I want to make action. if temperature > -10: do someting. elif temperature < 10: Do someting. But what is my problem? When I run microcontroler and actual temperature is -5.5. So I need to know how to specify the barier that when I´m already inside zone from -10 to 10 to do nothing. And when I break zone from outside to iside do what I want. I hope it´s clear. Can you help me how to solve it? Thank you so much :)

  • @navrozsalim6944
    @navrozsalim6944 ปีที่แล้ว

    legend

  • @greenishengland
    @greenishengland 4 ปีที่แล้ว

    Can we use If conditional statement without using else statement and print the else statement?

    • @MparRS
      @MparRS ปีที่แล้ว

      no

  • @ErkanOkman
    @ErkanOkman 5 ปีที่แล้ว +1

    👍👏

  • @sheikhrashid3055
    @sheikhrashid3055 3 ปีที่แล้ว

    How bag is greater than apple?

  • @sssapss
    @sssapss 2 ปีที่แล้ว

    How bag is smaller than cat?

  • @prosatisfyingdominoes1537
    @prosatisfyingdominoes1537 ปีที่แล้ว

    what app do you use for python

  • @rickybrenay6249
    @rickybrenay6249 2 ปีที่แล้ว

    💯

  • @kirans936
    @kirans936 4 ปีที่แล้ว

    Can I know the name of software used here plz 🙏

    • @sanjaysawant1975
      @sanjaysawant1975 4 ปีที่แล้ว +3

      hey friend you asked the name of software the name is "Visual studio code" if you want to know the theme name it is "Horizon italic"

  • @devdwr9208
    @devdwr9208 5 ปีที่แล้ว +3

    This is how works AI xD

  • @yuvrajwankhede8083
    @yuvrajwankhede8083 7 หลายเดือนก่อน

    I did not understand when he said "bag" is greater than "apple" because when we sort it comes before. can someone explain?

    • @jamaal1282
      @jamaal1282 หลายเดือนก่อน

      6 MONTHS LATE.... but Basically the alphabet. For example, b comes after A so therefore in programming B is greater than A and B does come before C therefore B is not greater than C.

  • @chungku7474
    @chungku7474 4 หลายเดือนก่อน

    What is it with bag, apple and cat, please help

    • @jamaal1282
      @jamaal1282 หลายเดือนก่อน

      Basically the alphabet. For example, b comes after A so therefore in programming B is greater than A and B does come before C therefore B is not greater than C.

  • @stephendgj
    @stephendgj 11 หลายเดือนก่อน

    did you make a mistake at 13.48 it should be > instead of

  • @rahmaelsayed2368
    @rahmaelsayed2368 หลายเดือนก่อน

    I have a big broblem in nasted if statment

  • @mattnowak2987
    @mattnowak2987 9 หลายเดือนก่อน

    Quick question dumb question how is bag greater than apple?

    • @jamaal1282
      @jamaal1282 หลายเดือนก่อน

      Basically the alphabet. For example, b comes after A so therefore in programming B is greater than A and B does come before C therefore B is not greater than C.

  • @AlexA-cj5my
    @AlexA-cj5my 5 ปีที่แล้ว +2

    It writes for me “TypeError: ‘

  • @ssegiriinyapaul816
    @ssegiriinyapaul816 10 หลายเดือนก่อน

    >>> temperature = 11
    ... if temperature > 11:
    ... print("Hot")
    ... print("drink water")
    >>> print("Done")
    SyntaxError: multiple statements found while compiling a single statement
    am using python 3.11.5, why do i get such a result?

  • @r0d1tub2
    @r0d1tub2 11 หลายเดือนก่อน

    why is bag not greater than cat. That I did not understand

  • @VaheOhanyan-ig7cj
    @VaheOhanyan-ig7cj ปีที่แล้ว

    what is this text editor's name?

    • @georgekomeh
      @georgekomeh 2 หลายเดือนก่อน

      Vs code

  • @samabdollahian9841
    @samabdollahian9841 4 ปีที่แล้ว

    The quiz for how b if false dosen't make sense

  • @lewisqiu5960
    @lewisqiu5960 ปีที่แล้ว

    Sorry i didn’t get it why bag great than apple And bag not great than cat. How can i tell

  • @al-harithodeh9121
    @al-harithodeh9121 9 หลายเดือนก่อน

    4:02 and 5:58 and 15:09

  • @naitiksingh8957
    @naitiksingh8957 10 หลายเดือนก่อน

    Sevy

  • @MRKAVYA079
    @MRKAVYA079 ปีที่แล้ว

    Me kya karu

  • @alfredo6307
    @alfredo6307 4 ปีที่แล้ว +1

    Some practice code I wrote. I think it works.
    response = input("Can you speak English? ")
    if response != "no":
    can_speak_english = True
    else:
    can_speak_english = False
    response2 = input("Can you speak Spanish? ")
    if response2 != "no":
    can_speak_spanish = True
    else:
    can_speak_spanish = False
    if can_speak_spanish and can_speak_english:
    print("You are eligible for a larger loan")
    else:
    print("You are eligible for a smaller loan")

    • @alfredo6307
      @alfredo6307 4 ปีที่แล้ว

      Update. It doesn't work 100% of the time properly

    • @sssapss
      @sssapss 2 ปีที่แล้ว

      it's wrong code

    • @asshivam8117
      @asshivam8117 2 ปีที่แล้ว

      th-cam.com/video/zO9Z4inmLzM/w-d-xo.html
      Topic : Control Flow and User Input in Python
      Department : CSE
      By Aditya(IIT DELHI)
      Notes available in Description
      Like, Share and Comment on the video
      Subscribe to the Ninepointers TH-cam Channel

    • @TaylorGang44
      @TaylorGang44 ปีที่แล้ว

      i'm pretty sure your code is wrong sir, lol you're giving the same response to both option

    • @thelmaajomiwe1059
      @thelmaajomiwe1059 8 หลายเดือนก่อน

      If can only come ones while elif comes as many as u want then close with else

  • @someXone
    @someXone 2 ปีที่แล้ว +1

    That elif is mistaken of else.
    Or
    It is actually elif.
    Someone please response.
    That 15:32 part is too confusing for me 😭

    • @David91777
      @David91777 2 ปีที่แล้ว

      No, from what I understand, it is meant to be elif.
      You use elif as a substitute condition in case the “if” statement doesn’t work. But if both the “if” and “elif” statements are not true, then it will print the “else” condition.
      I hope you understand this, but I’m a new programmer who only started this week, so don’t rely on my explanation as I could be wrong. 🙏🏾

    • @someXone
      @someXone 2 ปีที่แล้ว

      @@David91777 Thanks mate for response
      Yhh, i asked one of my friends in this elif confusion and he told about the use of elif as it is used as substitute and i understand how it works in python
      And i’m also newbie to this.
      I hope you also doing good. #Happylearning

    • @David91777
      @David91777 2 ปีที่แล้ว

      @@someXone Thanks very much man… Good luck and stay blessed. 🙏🏾

  • @lilskely6278
    @lilskely6278 3 ปีที่แล้ว

    wait so in 15:20 because b comes after a it will turn true and c comes after b so bag will become false in conclusion this will not be grater than cat, srls i never knew that this could happen in python!

    • @someXone
      @someXone 2 ปีที่แล้ว

      Exactly me too.
      This is my first time learing python and my mind is blowing up rn

  • @RadicalEdward_115
    @RadicalEdward_115 4 ปีที่แล้ว +1

    Just add the spaces lol, your already typing in that area. Dont teach bad habbits