Day-1-Basics - Ipynb - Colaboratory
Day-1-Basics - Ipynb - Colaboratory
ipynb - Colaboratory
# Variables ( placeholders ) we can store values inside a variable
x=10 # int # storing 10 inside x vaiable # = is ass
y=12.22 # float type vaiables
z='welcome in python lecture' # String value
w=True # boolean True/False
p='A' # String
print("value of x is =",x) # ctrl+enter ( run our program)
print("value of y is =",y)
print("value of z is =",z)
print("value of w is =",w)
print("value of p is =",p) # print is a predefiend function to display output
value of x is = 10
value of y is = 12.22
value of w is = True
value of p is = A
# how to check data type of variables
print("type of x is =", type(x)) # type is a predefined function
print("type of y is =", type(y))
print("type of z is =", type(z))
print("type of w is =", type(w))
print("type of p is =", type(p))
# Arithmetic Operators
x=16
y=3
print("x+y =", x+y)
print("x-y =", x-y)
print("x*y =", x*y)
print("x/y =", x/y)
print("x//y =", x//y) # this will skip decimal part (keep only int value) [floor div
print("x%y =", x%y) # this will return remaining part after a division [remainder
print("x**y =", x**y) # power
x+y = 19
x-y = 13
x*y = 48
x/y = 5.333333333333333
x//y = 5
x%y = 1
x**y = 4096
https://colab.research.google.com/drive/139IcuK1RHCFoLNjNW96rBRosT9ndtI2C#scrollTo=yFLtt2ZI-IDV&printMode=true 1/4
4/17/22, 8:30 PM Day-1-Basics.ipynb - Colaboratory
# comparision operator
x=40
y=20
print("x < y =", x < y , "###x is less than y###")
print("x > y =", x > y)
print("x <= y =", x <= y)
print("x >= y =", x >= y)
print("x == y =", x == y) # equal to
print("x != y =", x != y) # not eqaul to !(not)
x > y = True
x <= y = False
x >= y = True
x == y = False
x != y = True
# how change data type of variable
x=12.22
print(type(x)," ====> ",x)
y=int(x) # converting float value into integer
print(type(y)," ====> ",y)
x=123
print(type(x)," ====> ",x)
y=str(x) # converting integer into string
print(type(y)," ====> ",y) # we can not use this value for the calculation
x=True
print(type(x)," ====> ",x)
y=int(x) # converting bool into int (True is 1)(False is 0)
print(type(y)," ====> ",y)
x="5250"
print(type(x)," ====> ",x)
y=int(x) # converting String into integer
print(type(y)," ====> ",y) # we can use this value for the calculation
https://colab.research.google.com/drive/139IcuK1RHCFoLNjNW96rBRosT9ndtI2C#scrollTo=yFLtt2ZI-IDV&printMode=true 2/4
4/17/22, 8:30 PM Day-1-Basics.ipynb - Colaboratory
x="A"
print(type(x)," ====> ",x)
y=ord(x) # converting String into integer [Ascii value]
print(type(y)," ====> ",y) # we can use this value for the calculation
x=65
print(type(x)," ====> ",x)
y=chr(x) # converting int into String [Ascii value]
print(type(y)," ====> ",y) # we can use this value for the calculation
# how to take user input
name= input("please enter your name")
print("welcome"," ",name)
x=int(input("please enter x value")) # input is a predefined function to take user i
y=int(input("please enter y value"))
z=x+y # logic (calculation)
print("output z =",z)
output z = 44
# find out area of triangle
# area = 1/2*(l*b)
l=float(input("please enter l value")) # input always receive value in string
b=float(input("please enter b value")) # convering value as per our requirement
area=(l*b)/2
print("area is =", area)
area is = 7.476000000000001
https://colab.research.google.com/drive/139IcuK1RHCFoLNjNW96rBRosT9ndtI2C#scrollTo=yFLtt2ZI-IDV&printMode=true 3/4
4/17/22, 8:30 PM Day-1-Basics.ipynb - Colaboratory
https://colab.research.google.com/drive/139IcuK1RHCFoLNjNW96rBRosT9ndtI2C#scrollTo=yFLtt2ZI-IDV&printMode=true 4/4