1. Lecture 1:- print, id, type, basic data type (integer, float, string)
print('this is first python class') #this is first python class
print("hello student");print("welcome at inception") #hello student #welcome at inception
# This is single line comment
'''
this is multiline comment
welcome at inception.
'''
a=10
print(type(a)) #<class 'int'>
b=12.2
print(type(b)) #<class 'float'>
c='hello'
print(type(c)) #<class 'str'>
d="hello"
print(type(d)) #<class 'str'>
e='''hello
how are you'''
print(type(e)) #<class 'str'> #used for multiline string
f="""hello
how are you"""
print(type(f)) #<class 'str'> #used for multiline string
g=10
print(type(g)) #<class 'int'>
#id of a and e is equal because both refer to same value
#so value are stored at one place rather than multiple place
#same concept are used in facebook for photo storing
print(id(a)) #1522298624
print(id(g)) #1522298624
print(id(b)) #2240465414760
print(id(c)) #2321848675664
print(id(d)) #2321848675664
print(id(e)) #2321848802664
print(id(f)) #2321848802664
n=input("Enter any number")
print(type(n))
#Enter any number11
#<class 'str'>
n=int(input("Enter any number"))
print(type(n))
#Enter any number12
2. #<class 'int'>
n=float(input("Enter any number"))
print(type(n))
#Enter any number2.3
#<class 'float'>
a=10
b=20
print(id(a)==id(b))
#False
c=10
print(id(a)==id(c))
#True
3. Lecture 2:- multi datatype declaration, input, eval, sqrt, fabs, comparison operators,if,else
#this is single line comment
a=b=10
print(a,b)
#10 10
#swap of two number
a,b=10,20
a,b=b,a
print("a:",a,"b:",b)
#a: 20 b: 10
#swap of two number
a=eval(input("enter first number"))
b=eval(input("enter first number"))
x,y=a,b
a,b=b,a
print("value of", x, "and", y, "after swap",a,b)
#enter first number10
#enter first number20
#value of 10 and 20 after swap 20 10
#temperature in Celsius and Fahrenheit
c=eval(input("enter temperature in Celsius"))
f=((9/5)*c)+32
print("temperature in Celsius", c,"is",f,"in Fahrenheit")
#enter temperature in celcius37
#temperature in Celsius 37 is 98.60000000000001 in Fahrenheit
c=(f-32)*(5/9)
print("temperature in fahernite",f,"is",c, "in celcius")
#temperature in fahernite 98.60000000000001 is 37.00000000000001 in celcius
print(9/5) #1.8
print(9//5) #1
import math
a=math.sqrt(4)
print(a) #2.0
from math import sqrt
a=sqrt(4)
print(a) #2.0
#find hypotenuse of triangle
b=eval(input("enter base of triangle"))
h=eval(input("enter height of triangle"))
import math
4. hy=math.sqrt(h*h+b*b)
print("hypotenuse of triangle with height",h,"and base",b,"is",hy)
#enter base of triangle3
#enter height of triangle4
#hypotenuse of triangle with height 4 and base 3 is 5.0
#find hypotenuse of triangle
from math import sqrt
hy=sqrt(h*h+b*b)
print("hypotenuse of triangle with height", h, "and base",b,"is",hy)
#hypotenuse of triangle with height 4 and base 3 is 5.0
from math import fabs
a=fabs(-4)
print(a) #4.0
#comparison operators
a=eval(input("enter first number:"))
b=eval(input("enter second number:"))
if(a<b):
print("a=",a,"is less than b=",b)
if(a>b):
print("b=",b," is less than a=",a)
if(a==b):
print("b=",b," is equal to a=",a)
if(a<=b):
print("b=",b," is less or equal to a=",a)
if(a>=b):
print("b=",b," is greater than or equal to a=",a)
if(a!=b):
print("b=",b," is not equal to a=",a)
#b= 10 is less than a= 50
#b= 10 is greater than or equal to a= 50
#b= 10 is not equal to a= 50
5. Lecture 3: String, id, while, end
print('He said,"Ram is honest"')
#He said,"Ram is honest"
#string
s='hello'
print(s,type(s)) #hello <class 'str'>
s1="hello"
print(s1,type(s1)) #hello <class 'str'>
s2='''hello'''
print(s2,type(s2)) #hello <class 'str'>
s3="""hello"""
print(s3,type(s3)) #hello <class 'str'>
s="hello inception"
print(s[3:5]) #lo
print(s[6:15]) #inception
print(s[-1:]) #n
s="Hello Inception"
#slicing of string
s="Hello Inception"
print(s[6:-1])
#'Inceptio'
print(s[-1:-10])
#'' print nothing
print(s[-1:-9])
#'' print nothing
print(s[-9:-1])
#'Inceptio'
print(s[14:0])
#'' print nothing
#while loop
i=1
while(i<=10):
print(i,end=" ") #print value in one line
i=i+1
else:
print("bye")
#perfect square
from math import sqrt
a=eval(input("enter any number"))
b=sqrt(a)
if(a==b*b):
6. print(a,"is a perfect square")
else:
print(a,"is not perfect square")
#enter any number25
#25 is a perfect square
7. Lecture 4: for loop, and, or
for i in range(0,5):
print(i, end=" ")
#0 1 2 3 4
for i in range(0,10,2):
print(i,end=" ")
#0 2 4 6 8
for i in range(10,0,-2):
print("n",i,end=",")
#10,8,6,4,2
a=10
b=20
c=10
if(a!=c) or (b<a):
print('hi')
else:
print("hello")
#hello
#largest of three number
a=eval(input("enter first no."))
b=eval(input("enter second no."))
c=eval(input("enter third no."))
if(a>b) and (a>c):
print(a,"is largest")
else:
if(b>a) and (b>c):
print(b,"is largest")
else:
print("c is largest")
#leap year
y=eval(input("Enter year"))
if (y%4==0):
if(y%100==0):
if(y%400==0):
print("leap year")
else:
print("not leap year")
else:
print("leap year")
else:
print("not leap year")
8. #check number power of 3
n=eval(input("enter number"))
while(n%3==0):
n=n/3
if(n==1):
print("power of 3")
else:
print("not power of 3")
9. Lecture 5: for loop break, continue and pass
# check if an integer is power of another integer
n1=eval(input("Enter integer"))
n2=eval(input("ckeck for integer"))
while(n1%n2==0):
n1=n1/n2
if(n1==1):
print("power of ",n2)
else:
print("not power of ",n2)
#break demonstration
for i in range(14):
if(i==5):
break
print(i)
print("good bye")
#continue demonstration
for i in range(14):
if(i==5):
continue
print(i)
print("good bye")
#pass demonstration
for letter in 'python':
if (letter=='h'):
pass
print("this is pass")
print("current letter",letter)
print("bye")
hggggggg
#sum of N number
n=eval(input("Enter no."))
sum=0
for i in range(0,n+1):
sum=sum+i
#print(sum)
print("Sum is:",sum)
#Enter no.10
#Sum is:55
#sum of evenand odd number up to N
n=eval(input("Enter the numbers"))
even=0
10. odd=0
for i in range(0,n+1):
if(i%2==0):
even=even+i
else:
odd=odd+i
print("Sum of even numbers",even)
print("sum of odd numbers",odd)
#Enter the numbers34
#Sum of even numbers 306
#sum of odd numbers 289
#user defined function
def hello():
print("hello") #hello
hello()
#typical question
#add the digits of a positive integer repeatedly until the result has a single digit
def addsum(n):
s=0
while(n>0 or s>9):
if(n==0):
n=s
#print(n)
s=0
s=s+n%10
n=n//10
return s
n=eval(input("Enter any number:"))
print("sum in single digits ",addsum(n))
#Enter any number:65
#sum in single digits 2
11. Lecture 6: for loop, break, continue, recursion, chr and ord
#find factorial of number with recursion
def factorial(n):
if(n==1):
return 1
else:
return (n*factorial(n-1))
n=eval(input("Enter number:"))
if(n<0):
print("not valid")
elif(n==0 or n==1):
print("Factorial of",n,"is",1)
else:
print("Factorial of ",n,"is",factorial(n))
#Enter number:12
#Factorial of 12 is 479001600
#find factorial of number without recursion
n=eval(input("Enter number"))
if(n<0):
print("not valid")
elif(n==0 or n==1):
print("Factorial of",n,"is",1)
else:
f=1
while(n>1):
f=f*n
n=n-1
print("Factorial is",f)
#Enter number:12
#Factorial of 12 is 479001600
#chr and ord function
print(chr(97))
#'a'
print(ord('a'))
#97
#generate random password
c=''
for i in range(33, 128):
c=c+chr(i)
#print(c)
from random import choice
n=eval(input("Enter length of password"))
12. p=eval(input("Enter no. of passwords"))
print("Generated password is:")
for i in range(p):
password=''
for i in range(n):
password+=choice(c)
print(password)
#Enter length of password12
#Enter no. of passwords3
#Generated password is:
#b[&b_(2(9FMY
#=$4V29wn(A%$
#oLI3`J:lnQBf