```People = 30
Cars = 40
Trucks = 14
# line 1,2,3 assign the value to variables
If cars > people: Using if statement
Print(“we should take the  cars.”)
Elif cars < people: if 1st is false execute elif
print(“we should not take the car.”)
else : # if both are false then execute else:
print(“we can’t decide.”)

```
```People = 20
Cats = 30
Dogs = 15
# line 1,2 and 3 assigning values to variables
If people < cats: #1st condition
print(“too many cats”)
If people > cats: #2nd condition
print(“not many cats.”) # 3rd condition
If people > dogs:
print(“ the world is dry.”)

```
```x = int(input("Please enter an integer: "))
Please enter an integer: 42 #getting input from user
>>> if x < 0: #1st condition
...    x = 0
...    print('Negative changed to zero')
... elif x == 0: #2nd condition
...    print('Zero')
... elif x == 1: #3rd condition
...    print('Single')
... else: #4th condition
...    print('More')
```
``` 1. var = 100 # var is a variable.
2.if var < 200:
3.print "Expression value is less than 200"
4.if var == 150:
5.print "Which is 150"
6.elif var == 100:
7.print "Which is 100"
8.elif var == 50:
9.print "Which is 50"
10.elif var < 50:
11.print "Expression value is less than 50"
12.else:
13.print "Could not find true expression"

14.print "Good bye!"

When the above code is executed, it produces following result −
Expression value is less than 200
Which is 100
Good bye!
```
```1.People = 30
2.Cars = 40
3. Trucks = 14
# line 1,2,3 assign the value to variables
4.If cars > people: #Using if statement
5.Print(“we should take the  cars.”)
6.Elif cars < people: #if 1st is false execute elif
7.print(“we should not take the car.”)
8.else : # if both are false then execute else:
9.print(“we can’t decide.”)
```
bookmark
dashboard

Tue Apr 21 2020 11:15:59 GMT+0000 (UTC) https://www.amazon.com/Learn-Python-Hard-Way-Introduction/dp/0321884914

#python #python #condition #ifstatement #elifstatement #elsestatement
bookmark
dashboard

Tue Apr 21 2020 10:34:57 GMT+0000 (UTC) https://www.amazon.com/Learn-Python-Hard-Way-Introduction/dp/0321884914

#python #python #ifstatement #comparisonoperators
bookmark
dashboard

Tue Apr 21 2020 06:41:13 GMT+0000 (UTC) https://docs.python.org/3/tutorial/controlflow.html

#python #python #ifstatement #elifstatement #elsestatement #comparisonoperators
bookmark
dashboard

Mon Mar 30 2020 12:23:56 GMT+0000 (UTC) https://www.tutorialspoint.com/python/nested_if_statements_in_python.htm

#python #python #ifstatement #nestedif statement
bookmark
dashboard

Mon Mar 30 2020 12:04:52 GMT+0000 (UTC) https://www.amazon.com/Learn-Python-Hard-Way-Introduction/dp/0321884914

#python #python #ifstatement #elifstatement #elsestatement #comparisonoperators