Python Tutorial for Beginners 10 – Python elif and nested if Statements

///Python Tutorial for Beginners 10 – Python elif and nested if Statements

Python Tutorial for Beginners 10 – Python elif and nested if Statements

FavoriteLoadingAdd to favorites

In this Video I am going to show How to use Python IF…ELIF…ELSE Statements and nested IF statements in python. In python One conditional can also be nested within another.
The if statement evaluates a Boolean condition, and if it is True, performs the indented statements(or a block or code); but if the test is False, it does nothing. The if statement can have an optional else part which will be performed if the test result is False.
If you if condition expression contains logical operators then,
In (A and B), if A is false, then so is the expression, and there is no need to evaluate B
In (A or B), if A is true, then so is the expression, and there is no need to evaluate B

★★★Top Online Courses From ProgrammingKnowledge ★★★
Python Programming Course ➡️ ⚫️
Java Programming Course ➡️ ⚫️
Bash Shell Scripting Course ➡️ ⚫️
Linux Command Line Tutorials ➡️ ⚫️
C Programming Course ➡️ ⚫️
C++ Programming Course ➡️ ⚫️
PHP Programming Course ➡️ ⚫️
Android Development Course ➡️ ⚫️
C# Programming Course ➡️ ⚫️
JavaFx Programming Course ➡️ ⚫️
NodeJs Programming Course ➡️ ⚫️
Jenkins Course For Developers and DevOps ➡️ ⚫️
Scala Programming Tutorial Course ➡️ ⚫️
Bootstrap Responsive Web Design Tutorial ➡️ ⚫️
MongoDB Tutorial Course ➡️ ⚫️
QT C++ GUI Tutorial For Beginners ➡️

★★★ Online Courses to learn ★★★
Get 2 FREE Months of Unlimited Classes from skillshare –
Data Science – |
Machine Learning – |
Artificial Intelligence – |
MERN Stack E-Degree Program – |
DevOps E-degree – |
Data Analytics with R – |
AWS Certification Training – |
Projects in Java – |
Machine Learning With TensorFlow – |
Angular 8 – Complete Essential Guide –
Kotlin Android Development Masterclass –
Learn iOS Programming Building Advance Projects –

★★★ Follow ★★★
My Website –

DISCLAIMER: This video and description contains affiliate links, which means that if you click on one of the product links, I’ll receive a small commission. This help support the channel and allows us to continue to make videos like this. Thank you for the support!

python nested if else
python if statement multiple conditions
python if statement multiple lines
python 3 if else statement
python if elif
finally python
Python IF…ELIF…ELSE Statements

source

By |2020-01-15T01:13:34+00:00January 15th, 2020|Python Video Tutorials|25 Comments

25 Comments

  1. ProgrammingKnowledge January 15, 2020 at 1:13 am - Reply

    I have created the New Course on Python – Please Chick to View https://www.youtube.com/playlist?list=PLS1QulWo1RIYt4e0WnBp-ZjCNq8X0FX0J

  2. Ahmad Chawa January 15, 2020 at 1:13 am - Reply

    Agabeeeee
    Sen aptal mısın oğlum

  3. Madras Mic January 15, 2020 at 1:13 am - Reply

    lot of ads burst the concentration

  4. Sohaib Hassan Raza January 15, 2020 at 1:13 am - Reply

    Watch video at speed 1.50

  5. SIFISO SIHLALI January 15, 2020 at 1:13 am - Reply

    from flask import Flask,request,render_template
    app=Flask(__name__)

    @app.route("/")
    def index():
    return render_template("index.html")

    @app.route("/register",methods=["POST"])
    def register():
    if not request.form.get("name") or not request.form.get("surname"):
    return render_template("hluleka.html")
    return render_template("phumelela.html") it doesn't go through to this line.what am I doing wrong

  6. Shivani Singh January 15, 2020 at 1:13 am - Reply

    ur codes shows invalid syntax everytime especially in this if else condition

  7. ROHAN CHATTERJEE January 15, 2020 at 1:13 am - Reply

    I am trying to evaluate whether a number is even or odd by using the following code

    a=int(input("number"))
    if (a/2)==0:
    print("The number is even")

    else:
    print("The number is odd")

    But its showing me syntax error. Can someone me out?

  8. somu dutta January 15, 2020 at 1:13 am - Reply

    the best one out there till now this playlist has been of great help, thank you ,
    cheers!!

  9. divya singhal January 15, 2020 at 1:13 am - Reply

    Hi,
    i tried running the code:

    a = input("name")
    if name=="Divya":
    print("The name is",a)
    elif name!="Divya":
    print("the name is not",a)
    else:
    Print("name is inavlid")

    But it is failing. can you please tell why?

  10. Eric Avila January 15, 2020 at 1:13 am - Reply

    If only the video was in English, sigh!

  11. Usha Jain January 15, 2020 at 1:13 am - Reply

    keep going very very helpful

  12. chitra lalawat January 15, 2020 at 1:13 am - Reply

    # list of tallest tower sin the world
    x=input("enter tower name : ")
    if x=="tokyo" or "tokyo skytree" or "skytree":
    print("1st tallest and situated in japan")
    elif x=="canton" :
    print("2nd tallest and situated in China")
    elif x=="CN" or "CN tower":
    print("3rd tallest and situated in Canada")
    elif x=="Ostankino" :
    print("4th tallest and situated in Russia")
    elif x=="Oriental" or "Pearl" or "Oriental Pearl" :
    print("5th tallest and situated in China")
    elif x=="Milad" :
    print("6th tallest and situated in Iran")
    elif x=="Kuala" or "Lumpur" or "Kuala Lumper":
    print("7th tallest and situated in Malaysia")
    else:
    print("not world's tallest tower")
    I MADE THIS PROGRAM USING NESTED IF BUT ITS NOT WORKING… EVERYTIME I'M RUNNING, IT'S SHOWING- 1ST TALLEST AND SITUATED IN JAPAN… how can I rectify this program…do let me know..

  13. best person wins that is me January 15, 2020 at 1:13 am - Reply

    enterd spelling is wrong it should be entered

  14. saikrishna vemula January 15, 2020 at 1:13 am - Reply

    i tried like this

    gender=input("enter you gender m/f: ")
    if gender=="m":
    age=int(input("enter your age: "))
    if age>21:
    print("eligible for marriage")
    status=input("would you like to marry same one (yes/no) :")
    if status=="yes":
    print("go to our website http://www.marriage.com")
    input("enter to exit")
    elif status=="no":

    print("thank you for your valuable time")

    input("enter to exit")
    else:
    print("not valid statement")
    input("enter to exit")

    else:

    print("not eligible for marriage")

    input("enter to exit")

    elif gender=="f":
    age=int(input("enter your age: "))
    if age>18:
    print("eligible for marriage")
    status=input("would you like to marry same one (yes/no) :")
    if status=="yes":

    print("go to our website http://www.marriage.com")

    input("enter to exit")
    elif status=="no":
    print("thank you for your valuable time")
    input("enter to exit")

    else:
    print("not valid statement")

    input("enter to exit")
    else:
    print("not eligible for marriage")
    input("enter to exit")

    else:
    print("not valid")
    input("enter to exit")

  15. Vadiraja Venkatesh January 15, 2020 at 1:13 am - Reply

    nice

  16. muralidhar A January 15, 2020 at 1:13 am - Reply

    Hey, why are you writing comma(,) in print statement any specific reason?

  17. Jake Ambrose January 15, 2020 at 1:13 am - Reply

    zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz

  18. Sherwin Sherry.J January 15, 2020 at 1:13 am - Reply

    n=input("enter the name: ")
    if n==['mark','tom','rose','shane']:
    can we use this method to prevent the number or elif statements?

  19. ND Productions January 15, 2020 at 1:13 am - Reply

    Made a Quiz!!!

    Name = input("What is your name? ")
    Age = int(input("How old are you: "))
    x = "You answer is correct"
    y = "Your answer is incorrect"

    question = input("Which is the heavier metal of these two? Gold or Silver? ")
    if question == "Gold":
    print(x)
    else:
    print(y)

    questionTwo = input("Which is the most common non-contagious disease in the world? ")
    if questionTwo == "Tooth Decay":
    print(x)
    else:
    print(y)

    questionThree = input("Which is the coldest location in the earth? ")
    if questionThree == "East Antarctica":
    print(x)
    else:
    print(y)

    questionFour = input("Which is the hottest place in the earth? ")
    if questionFour == "Ethiopia":
    print(x)
    else:
    print(y)

    questionFive = input("Which is the animal referred as the ship of the desert? ")
    if questionFive == "Camel":
    print(x)
    else:
    print(y)

    questionSix = input("Which is the nearest star to planet earth? ")
    if questionSix == "Sun":
    print(x)
    else:
    print(y)

    questionSeven = input("Which is the least populated country in the world? ")
    if questionSeven == "Vatican City":
    print(x)
    else:
    print(y)

    questionEight = input("Which is the oldest democracy / parliamentary in the world? ")
    if questionEight == "Britain":
    print(x)
    else:
    print(y)

    questionNine = input("Which is the fastest animal on the land? ")
    if questionNine == "Cheetah":
    print(x)
    else:
    print(y)

    questionTen = input("What differentiates a male lion from a female lion? ")
    if questionTen == "Mane":
    print(x)
    else:
    print(y)

    questionEleven = input("Which is the most sensitive organ in our body? ")
    if questionEleven == "Skin":
    print(x)
    else:
    print(y)

    questionTwelve = input("Which is the principal source of energy for earth? ")
    if questionTwelve == "Sun":
    print(x)
    else:
    print(y)

    questionThirteen = input("What are the two holes in the nose called? ")
    if questionThirteen == "Nostrils":
    print(x)
    else:
    print(y)

    questionFourteen = input("What is the standard taste of the water? ")
    if questionFourteen == "No Taste":
    print(x)
    else:
    print(y)

    questionFifteen = input("Which is the longest river on the earth? ")
    if questionFifteen == "Nile":
    print(x)
    else:
    print(y)

  20. Riley Wilkins January 15, 2020 at 1:13 am - Reply

    I'm getting the same problem that everyone else is getting (see below). I have 3.5.1
    Tried many things and unable to figure it out

  21. Vincent B January 15, 2020 at 1:13 am - Reply

    What if you want it to recognize the name as both 'tom' AND 'Tom'—-the one having an upper case letter and the one not?

  22. Vincent B January 15, 2020 at 1:13 am - Reply

    U guys I need help!! I have a competition tomorrow so any input ASAP would b help!!!

    So I have python 2.7.10
    I copied and pasted his code and I got:

    >>>
    Name? mark

    Traceback (most recent call last):
    File "C:/Python27/ElifStatements2.py", line 1, in <module>
    name = input("Name? ")
    File "<string>", line 1, in <module>
    NameError: name 'mark' is not defined

    —–but when i placed raw_input instead of input, it worked, only problem is it gave me this:

    name is?mark
    ('the name entered is', 'mark')
    >>>

    —-how can I get rid of the parenthesis and the single quotations that surrounds mark and the first argument?

  23. HumbleDays January 15, 2020 at 1:13 am - Reply

    Took me a while, but it was fun, thanks! 🙂

    age=int(input('What is your age?'))

    if age<0:
    print('That's impossible. Stop lying.')
    realAge=int(input('At least give me a realistic answer…'))
    if realAge>0:
    print('Thanks, I guess I will take that.')
    elif age<18:
    print('You are not an adult.')
    else:
    print('You are an adult.')
    gender=input('What is your gender?[M/F]')
    if gender=='M':
    print('You are a man.')
    elif gender=='F':
    print('You are a woman.')
    else:
    print('Please type either M or F to spefify your gender.')

    enter=input('Press enter to terminate program.')

  24. Sam Mirza January 15, 2020 at 1:13 am - Reply

    this is what I wrote (copied)

    name=input("name?")
    if name=="mark":
       print("the name entered is",name)
    elif name=="john":
        print("the name entered is", name)
    elif name=="july":
        print("the name entered is", name)
    elif name=="tom":
        print("the name entered is", name)
    else:
        print("the name entered is not valid")

     result in the shell:

    name?tom

    Traceback (most recent call last):
      File "C:/Python27/test.py", line 1, in <module>
        name=input("name?")
      File "<string>", line 1, in <module>
    NameError: name 'tom' is not defined
    >>>
    Anyone please help??? why and how to fix, where is the problem
    thanks

  25. MANOHAR REDDY January 15, 2020 at 1:13 am - Reply

    after this video i wrote this code

    gender=input('enter you gender [m/f]')
    if gender=='m':
        age=int(input('enter your age: '))
        if age>21:
            print('eligible for marriage')
        else:
            print('not eligible for marriage')
    elif gender=='f':
        age=int(input('enter your age: '))
        if age>18:
            print('eligible for marriage')
        else:
            print('not eligible for marriage')
    else:
        print('enter valid gender')

Leave A Comment

*