Python 3 Programming Tutorial: If Else

The If-Else statement is designed to build on the if statement’s logic. Here, we ask if something is the case, and, if it is we do something. Then we say otherwise, which is contingent on the previous if statement, do something else. If the previous if statement is true, then the else will not run. If the if statement is false, then the else statement will run.

Sample code for this basics series: http://pythonprogramming.net/beginner-python-programming-tutorials/

Python 3 Programming tutorial Playlist: http://www.youtube.com/watch?v=oVp1vrfL_w4&feature=share&list=PLQVvvaa0QuDe8XSftW-RAxdo6OmaeL85M

In this python programming tutorial video you are shown how to use the if-else statements together.

http://seaofbtc.com
http://sentdex.com
http://hkinsley.com
https://twitter.com/sentdex

Bitcoin donations: 1GV7srgR4NJx4vrk7avCmmVQQrqmv87ty6

Comments

Abdul Odud says:

Hi , I am getting error while executing if else block in python 3.6.4 IDE shell  but same thing when I am executing in Terminal , it’s working as expected . Could you please let me know the point of error.
IDE Code / Error :

>>> if x > y :
print (‘x’)
else :

SyntaxError: invalid syntax

Terminal : 

>>> if x>y:
…    print(‘x’)
… else :
…    print(‘y’)
y

Isaiah Trigo says:

python 3.6.ob4 is telling me the else statement and the elif statements are invalid syntax

sue mendez says:

I like the large font you use it’s easy to see the code, Thanks.

Free Pokemon TCG online codes says:

a=int(input(“How old are you?”))
if a >= 16 < 18: b=input("Are you at sixth form, work or at college?") print("You work at",b,".") if a > 18:
c=input(“Have you started taking driving lessons yet?”)

Why does this not work!!

Mr Hunterf says:

Thankyou, just starting to learn python. subscribed.

Andreas Paalman says:

I had a constant error with using else but thanks to your help i managed to create my first if else code and im really happy 😀
Thank you!

Justin Duijn says:

This one is confusing, because if if is true, else is not and if else is true, if is not true.
Confusing, but true, else, not true.

hangmanM1 says:

Here’s my code but it doesn’t go to the else statement if the if statement is false. Everything else works besides if statement. 

  1 #!/bin/python
  2 var = raw_input (“hey, what’s your name? “)
  3 print “hello,”, var, “nice to meet you. What do you like to do?”
  4 var = raw_input()
  5 print var, “? I like to do that as well!”
  6 print “what do you like to eat? “,
  7 var = raw_input()
  8 print “I like to eat” ,var, “as well! But, I also like your mother’s pussy. What is the temperature right now?”
  9 if raw_input() > 30:
 10   print (“As usual”)
 11 else:
 12   print (“That’s not possible”)
~
Any ideas y it won’t go to else statement?
Thanks in advance BTW.

andre johan says:

Best basic python series… even better than some of the paid courses!

great work

Noah Sanchez says:

1:21 TTTRRRRIIIGGGEEERRRREEEDDD

Freddy Camacho says:

Does python have data vectors like c++?

Logan Burke says:

please, someone help me… This code is not working
age = input()
if age > int(13) :
print(“You can take this test :)”)
else:
print (“You can’t take this test.”)
print (” But I am really nice so I’m going to let you take it “)
print (“Are you ready?”)

L o n l y says:

I know it sounds stupid but I want to make a software where u type a gun name in fortnite but I only can do one gun.i need help

John Bannister says:

You’re great at explaining this stuff man, thank you for posting these vids- very helpful

Mizou Drs says:

I wonder to know if there is a function that can solve such problem, imagine we have :
a = 56123145678561615615615616515665156123145678561615615615616515665156123
b = 56123145678561615615615616515665156123145678561615615615616515665157123
numbers in A and B, seem to be equal but there is only one number which is not the same in B , is’t possible to know what is the unmatched number in B using python ?

U2bingDummy says:

Actually, I know the if else and elif functions for Python. I’ve been working on a project that can detect if Radiostations are on the air or not. But I need someone to give me the source code of a program that can detect sound. Can you help?

Haily Melendez says:

I have to go to your videos because my computer programming teacher isn’t great at explaining and I would like a nice grade. Thanks!

Muhammad Usama says:

sir its so complicated and not understand

isaac johnson says:

Thankyou for this video it really helped me do my homework :)

RankBabie Rank says:

I wrote some code with multiple input statements at once for a simple RPG inventory tutorial. are you able to do that because it runs the if statement even lg the condition is not true. Ex.
looting = input(“Do you wish to continue?nyes or no.”)
if looting == “yes” or “Yes”:
print(“Your character has just defeated a ‘Basic Rouge'”)
with some other input staments in here.
then at the bottom is
else:
print(“I’m sorry you must have typed that wrong. You must restart the tutorial.”)
But even if i put 10 random letters in its still goes to the if statement and not the else.
pls reply as fast as you can this is due tomorrow. its ok if you don’t.

ahowl7mx says:

Great series Sentdex, you helped me learn python over a weekend! General question, how do you make a new column and have an if-then statement in the new column? Example, I have two columns with different string lengths and I want a new column that will use either column if the length of the string is 13.

RagHelen says:

I once had a girlfriend named Elif.

Atomic Potato says:

How can you do this with variables that have an input e.g.
understand = input(‘is that understood?’)
if understand == yes
print(‘good, now lets move on’)

Princeton A. Strong says:

Thanks for the tutorials!

Hidden Acc says:

How x is greater than 55 when x is 5 you dumm dumm

Liam Blyth says:

I have doneif phone=android:       print (“yay”)what is wrong?? please help

Write a comment

*

Human Verification: In order to verify that you are a human and not a spam bot, please enter the answer into the following box below based on the instructions contained in the graphic.


Do you like our videos?
Do you want to see more like that?

Please click below to support us on Facebook!

Send this to a friend

▷ Other ReviewsVehicles▷ Show Cars▷ Motorbikes▷ Scooters▷ Bicycles▷ Rims & Tires▷ Luxury BoatsFashion▷ Sunglasses▷ Luxury Watches▷ Luxury Purses▷ Jeans Wear▷ High Heels▷ Kinis Swimwear▷ Perfumes▷ Jewellery▷ Cosmetics▷ Shaving Helpers▷ Fashion HatsFooding▷ Chef Club▷ Fooding Helpers▷ Coktails & LiquorsSports▷ Sport Shoes▷ Fitness & Detox▷ Golf Gear▷ Racquets▷ Hiking & Trek Gear▷ Diving Equipment▷ Ski Gear▷ Snowboards▷ Surf Boards▷ Rollers & SkatesEntertainment▷ DIY Guides▷ Zik Instruments▷ Published Books▷ Music Albums▷ Cine Movies▷ Trading Helpers▷ Make Money▷ Fishing Equipment▷ Paintball Supplies▷ Trading Card Games▷ Telescopes▷ Knives▷ VapesHigh Tech▷ Flat Screens▷ Tech Devices▷ Camera Lenses▷ Audio HiFi▷ Printers▷ USB Devices▷ PC Hardware▷ Network Gear▷ Cloud Servers▷ Software Helpers▷ Programmer Helpers▷ Mobile Apps▷ Hearing AidsHome▷ Home Furniture▷ Home Appliances▷ Tools Workshop▷ Beddings▷ Floor Layings▷ Barbecues▷ Aquarium Gear▷ Safe Boxes▷ Office Supplies▷ Security Locks▷ Cleaning ProductsKids▷ Baby Strollers▷ Child Car Seats▷ Remote ControlledTravel▷ Luggages & Bags▷ Airlines Seats▷ Hotel Rooms▷ Fun Trips▷ Cruise Ships▷ Mexico Tours