Python Practical-102 Sem-1

 #Python-102 Sem-1

#first practical:-

#-1.1--installation and type 

a="faizan alam"

b=1

print(type(a))


print(type(b))

#1.2--print name with design


name = input("Enter Name:")

print("*"*40)

print("Welcome to Python mr/ms:",name)

print("*"*40)

#1.3--get 5 input and give avg of 3 and 5 number


print("*"*40)

a = int(input("Enter number 1:"))

b = int(input("Enter number 2:"))

c = int(input("Enter number 3:"))

print("The average of the three number is:",(a+b+c)/3)

print("*"*40)

d = int(input("Enter number 4:"))

e = int(input("Enter number 5:"))

print("The Average of five number is:",(a+b+c+d+e)/5)

print("*"*40)


#second Practical

#-2.1--calculating persentage

a = int(input("Enter number 1:"))

b = int(input("Enter number 2:"))

c = int(input("Enter number 3:"))

total = (a+b+c)/300

persent = total*100

print("The persentage of the three number that you entered is:",persent)


#-2.2--calculate simple interest

a = int(input("Enter number 1:"))

b = int(input("Enter number 2:"))

c = int(input("Enter number 3:"))

s = (a*b*c)/100

print("The simple Interest of the given info is:",s)


#-2.3--write a program and print the element of list

lst = [1,2,3,5,6,8,9,22,33,44,42,55,53,66,64,63,77,75,74,74]

for i in range (0, 15):

    if lst[i]>0:

        print(lst[i])


#Third Practical

#-3.1--write a progrma whether a number is even or odd

print("Program to identify even or odd number")

print("*"*40)

num = int(input("Enter number:"))

if (num%2 ==0):

    print(num,"The given number is even number")

else:

    print(num,"The given number is odd number") 


#-3.2--Write a program to find the greatest of three number

print("Please do Enter three number below")

a = int(input("Enter number 1:"))

b = int(input("Enter number 2:"))

c = int(input("Enter number 3:"))

if a>b and a>c:

    print(a,"value is greater than ",b,"and",c)

elif b>a and b>c:

    print(b,"value  is greater than ",b,"and",c)

else:

    print(c,"value  is greater than ",a,"and",b)


#-3.3--Write a program to write absolute of number

print("Program to write the absolute value of number")

print("*"*40)

a = int(input("Enter number:"))

if (a<0):

    print("Absolute of ",a,"is ",(a*-1))

else:

    print("Absolute  of", a ,"is",a)


#Forth Practical

#-4.1--program to make table

print("Program to print the mathematical table")

print("-"*40)

a = int(input("Enter number:"))

i=1

while(i<=10):

    print(a,"x",i,"=",(a*i))

    i=i+1


#-4.2--program to accept number and print its factorial

def fact(x):

    while x>0:

        if x==1:

            return 1

        else:

            return(x*fact(x-1))

v=int(input("Enter number:"))

print(fact(v))



#-4.3--program to  print all even number btw 15 to 100

print("All even number between 15 to 100 ")

i=15

while(i<=100):

    if(i%2==0):

        print(i)

    i=i+1 


#-4.4--program to print Fibonacii series upto n terms

print("Program to print Fibonncci series")

n = int(input("Enter number of terms:"))

a=0

b=1

c=1

print(a,b,end=' ')

for i in range (3,(n+1)):

    c=a+b

    print(c,end=' ')

    a=b

    b=c


#-4.5--program to print pattern using nested loop

print("Program to print pattern")

for i in range(1,6):

    for j in range (1,i+1):

        print('*',end=' ')

    print()


#Fifth Practical

print("Program to study of string function")

print('-'*40)

a="hello fycs students hope you find this blog helpful"

print(a)   #will print the whole { a }

print("first letter:", a[0])  #do remember the counting start from zero not one

print("First ten letter:",a[0:10])

print("count of s",a.count('s')) #you can change the s and write you own alphabet

print("Split at whilespace",a.split(' ')) # it will make list of all the word present in var-a

print("Start with r:",a.startswith('r'))  #since first word start with h it will come false

print("Start with h:",a.startswith('h'))

print("Ends with d:",a.endswith('d'));print("Ends with l",a.endswith('l'))

print("replace word student:",a.replace("students","baccho"))

print("lowercase:",a.lower())

print("Capitalize:",a.capitalize())

print("Sentence case:",a.title())

print("Uppercase:",a.upper())

print("swap case(toggle):",a.swapcase())


#Sixth Practical

list1=[3,5,6,7,1]

print(list1);print(list1[2:5]);print(list1[3:])


list2=['a','b','c','d','e','f']

print(list2);print(list2[2:5])


list3=list1+list2

print(list3)


list3[1]=9  #will replace to 9 at position 1

print(list3)


del(list3[2]) #will delete no. in position 2

print(list3);print(list3*2) #will print list3 two times


for i in list3:

    print(list3)


print("Does 3 exist in list 3?",3 in list3)

print("total number of 4 in list3:",list3.count(4))


list3.append(8)   #will add 8 in list 3

print(list3)


list3.reverse()

print(list3);print("length of list3:",len(list3))


list1.sort()

print("sort of list1:",list1)

list2.sort()

print("sort of list2:",list2)


#Seventh Practical

#difference btw list and tuples..in list square brck is use and in tuple parenthese

tup1=(1,2,3,4,5)

print(tup1);print(tup1[2:4]);print(tup1[2:])


tup2=('a','b','c','d')

print(tup2);print(tup2[2:4]);print(tup2[2:])


tup3=tup1+tup2

print(tup3);print(tup3*2)


for i in tup3:

    print(tup3)


print("Does 8 exist in tup3?", 8 in tup3)

print("total number of 4 in tup3:",tup3.count(4))

print("length of tup3",len(tup3))

#tup1.sort()     

#print("sort of tup1",tup1) #tuple has no sort attribute therefore it will show error


print("minimum of tup1:",min(tup1),"\nmaximum of tup1",max(tup1))


#Eighth Practical

#-8.1--Program to display name

def msg(name):

    print(name,"is a def function in python")

name=input("Enter name:")

msg(name)


#-8.2--Program to calculate square root using function

def square(n):

    return(n**2)

print("Program to calulate square of number")

n=int(input("Enter num:"))

print("square of",n,"is",square(n))

s=square(n)


#-8.3--Program to print all even number till n terms

def myeven(n):

    for i in range(1,n+1):

        if(i%2==0):

            print(i,end=' ')

print("Even number list")

n=int(input("Enter the n number:"))

myeven(n)


#-8.4--Program to print factorial

def factorial(n):

    fact=1

    for i in range(1,n+1):

        fact=fact*i

    return (fact)

print("factorial program:")

n=int(input("Enter number:"))

print("Factorial of",n,"is",factorial(n))


#Ninth Practical

#-9.1--Program to implement Math module

import math

print("Ceiling of 5.4",math.ceil(5.4))

print("Floor of 5.4",math.floor(5.4))

print("Absolute of -32",math.fabs(-32))

print("4 raised to 5",math.pow(4,5))

print("exponent aised to 4",math.exp(4))

print("pie is",math.pi)

print("exp",math.e)

print("sin(pi/2):",math.sin(math.pi/2))


#-9.2--Program to call function from calulator module

def add(a,b):

    return(a+b)

def sub(a,b):

    return(a-b)

def multiply(a,b):

    return(a*b)

def division(a,b):

    return(a/b)

a=int(input("Enter number1:"))

b=int(input("Enter number2:"))

print("addition",add(a,b))

print("subtraaction",sub(a,b))

print("multiply",multiply(a,b))

print("division",division(a,b))


Comments

Post a Comment