2. Objective
Inputs in python
Ready functions in python
Conditions in python
If statement
3. Inputs in python
First when we want to write a python program we must install a compiler
or must create a new python file and run it using the shell
When we want to make user input from the keyboard we use the keyword
(input)
Example: x=input()
In this case the shell will wait us for input from keyboard
We can show a message before input
Example: y=input(‘input something’)
Rule: every thing we input it from keyboard it
inputted as string
4. Ready functions in python
After we input some thing from keyboard as string
If we want to convert the input to another data type we must use some
ready function as:
int(): to convert to int
Example: int(x)…. Then x will be an int variable
float(): to convert to float
Example: float(y)…… then y will be a float variable
str(): to convert to string
Example: str(5)…. Then the 5 will be like ‘5’ as a string
Rule: we can use this functions in print command
5. Conditions in python
In python we have only (if statement)
There is no switch….case statement
If we want to implement (switch….case) statement we must create a new
function for this
Rule: in python there is only if statement
6. If statement
As all programming languages the if statement has the following syntax:
if condition :
commands
7. If … else statement
The syntax is:
if condition:
command
else:
command
8. If … elseif … else statement
The syntax is:
if condition:
command
elif condition:
command
else:
command
9. The biggest number
x=5
y=6
z=10
if x>y and x>z:
print('the biggest number is: ',x)
elif y>x and y>z:
print('the biggest number is: ',y)
else:
print('the biggest number is: ',z)
10. The biggest number
x=int(input('enter the first number: '))
y=int(input('enter the second number: '))
z=int(input('enter the third number: '))
if x>y and x>z:
print('the biggest number is x: ',x)
elif y>x and y>z:
print('the biggest number is y: ',y)
else:
print('the biggest number is z: ',z)