3.Phython
3.Phython
>>> 2 + 2
Type and Check the Result
IDLE editor
Variables
You want to give a value a name
a = 123
b = 12.34
c = "Hello"
d = 'Hello'
Enter Value:23
>>> print(x)
23
Arithmetic
>>> print(y)
29.75
Arithmetic
% (modulo remainder)
** (raise to the power of)
>>> 10% 2
>>> 10% 3
>>> 4**2
>>> 9**2
Escape Characters
For tab \t
Newline \n
Name Age
Rama 14
>>> print(s)
Running Commands Conditionally
x=input("enter x value:")
if int (x)>100:
else:
== Exactly equal to
!= Not equal to
Compare the x value with 100 and print
corresponding message.
x = input("enter x value:")
if int (x)>100:
elif int(x)==100:
else :
>>> 1 != 2 >>> 10 == 10
True True
>>> 10 >= 11
False
Logical Operators
The logical operators:
x=input("enter x value:")
else :
print(‘BASU’)
Repeating Instructions Until Some Condition
Changes
while (count<9):
count = count+1
Breaking Out of a Loop
var = 10
while var > 0:
print ('Current variable value :', var)
var = var -1
if var == 5:
break
Defining a Function in Python
Example
def say_hello():# block belonging to the function
print('hello world') # End of function
x = input("enter X value:")
y = input("enter y value)
print_max (x, y) # pass variables as arguments
Function in Python
• The return statement is used to return from a function i.e. break
out of the function.
def print_max (a, b):
if a > b:
return a
elif a == b:
return " x and y are equal"
else:
return b
while True:
x = input("enter X value:”)
y = input ("enter y value")
print(print_max (x, y))
THANK YOU