IF Statement in Python
to be able to put a test or a certain condition , if statement should be added
Ex. if the age of a person is less than 18 , he can not drive a car . if Not
( bigger than ) he can drive a car
let us translate above mentioned word to be a program in python
age = eval( input ( " age = "))
if age <18 then
Print(" you can not drive ")
Endif
If ( age < 18) : if the answer is true or right immediately the
next line is executed
print (" you can not drive ")
Endif
if you focused in above program we will deduct the following
1- if the answer of question ( if age < 18) is age less than 18 ? answer is YES or TRUE
that is mean this person can not drive a car
2- the next line will be executed immediately in case the answer of if statement is true
3- if the answer of question or statement if ( if age < 18) that is mean his age if bigger
than 18 ? answer will be FALSE or NO the program will go to ENDIF to finish the
program
Cont. If statement with testing two cases Else statement
2020-03-11 [Link]
if ( age <18 ):
print ("you can not drive) in case of true your age is less than
18 and go to ENDIF
else in case of False your age is bigger
than 18 and go to Endif
print (" you can drive a car" )
endIf
comparison and logical operators
2020-03-11 [Link]
Many of the conditions you will work with depend on a compriosn of variables .
the result is a boolean ( True or False)
== equal
!= Not equal
< less than
<= less than or equal
> Greater than
>= Greater or equal