PLC Lab Programs
PLC Lab Programs
Write a program to read the student details like Name, USN, and Marks in
three subjects.Display the student details, total marks and percentage with
suitable messages
name=input("Enter student name")
usn=input("Enter student USN")
sub1=input("Enter subject1 marks")
sub1=int(sub1)
sub2=input("Enter subject1 marks")
sub2=int(sub2)
sub3=input("Enter subject1 marks")
sub3=int(sub3)
total_marks=(sub1+sub2+sub3)
perce_marks=(total_marks/300)*100
print("-----------------------------------------------------")
print("Stuudent name :-", name)
print("Student USN :-",usn )
print("Total marks of all three subjects is:-",total_marks)
print("Average of all the three subject is:-",perce_marks)
if(perce_marks>=70):
print(name+" "+ "is passed in Distinction")
elif(perce_marks>=60 and perce_marks<=70):
print(name+" "+ "is passed in First Class")
elif(perce_marks>=50 and perce_marks<60):
print(name+" "+ "is passed in Second Class")
elif(perce_marks>=35 and perce_marks<50):
print(name+" "+ "is passed in below second class")
else:
print(name+" "+ "is Failed")
print("-----------------------------------------------------")
1.b. Develop a program to read the name and year of birth of a person.
Display whether the person is a senior citizen or not
def factorial(m):
fact=1
for i in range(1,m+1):
fact=fact*i
return fact
n=input("Enter n value")
n=int(n)
nfact=factorial(n)
r=input("Enter r value")
r=int(r)
rfact=factorial(r)
nr=n-r
nrfact=factorial(nr)
bin_coef=nfact/(rfact*nrfact)
print("The binimial coefficient result is :-", bin_coef)
3. Read N numbers from the console and create a list. Develop a program
print mean , variance and standard deviation with suitable message.
import numpy as np
l1=[] # initially l1 list is empty
n=1 # initial value of n=1
print(“Enter list elements until ‘0’ press”)
while (n!=0): # new elements are added at the end of the list
until n=0, breaks the while loop
n=input()
n=int(n)
if(n==0):
break
l1.append(n)
print("All the elements in the list are ")
print(l1)
print("Average of all the elements in the list are")
print(np.average(l1))
print("Variance of all the elements in the list are")
print(np.var(l1))
print("Standard deviation of all the elements in the list are")
print(np.std(l1))
4. Read a multi-digit number (as chars) from the console. Develop a program
to print the frequency of each digit with suitable message
# Initialize limit
N = 6
# printing result
print("First " + str(N) + " elements in dictionary is : ")
print(str(out))
infile = open('D:\g.txt','r')
words = []
for line in infile:
temp = line.split()
for i in temp:
words.append(i)
infile.close()
print(words)
words.sort()
print(words)
outfile = open("result2.txt", "w")
for i in words:
outfile.writelines(i)
outfile.writelines(" ")
outfile.close()
import zipfile
newzip=zipfile.ZipFile('new6.zip','w')
newzip.write('D:\g.txt',compress_type=zipfile.ZIP_DEFLATED)
newzip.close()
def display(self):
print(self.realPart,"+",self.imgPart,"i", sep="")
c1 = Complex()
c2 = Complex()
c3 = Complex()
print("Enter first complex number")
c1.initComplex()
print("First Complex Number: ", end="")
c1.display()
10. Develop a program that uses class student which prompts the
user to enter marks in three subjects and calculate total marks
,percentage and displays the score card details.[Hint. Use list
to store the marks in three subjects and total marks.Use
__init__method to initialize name,USN,and the lists to store
marks and total.Use getMarks method to read marks into the list
and display() method to display the score card details]
class student:
def __init__(self,usn,name,marks):
self.usn=usn
self.name=name
self.marks=marks
def getMarks(self):
total_marks=0
print("The details of marks belongs to " + self.name + " is as
follows")
for i in self.marks:
print(i)
total_marks=total_marks+i
print("The total marks of all three subjects is :-
",total_marks)
def display(self):
print(self.usn)
print(self.name)
total_marks=0
avg_marks=0.0
print("The details of marks belongs to " + self.name + " is as
follows")
for i in self.marks:
print(i)
total_marks=total_marks+i
print("The total marks of all three subjects is
:- ",total_marks)
avg_marks=(total_marks/3)
print("The average of all three subjects is :-",avg_marks)
obj1=student('1DB22CS001','VEDANTA',[56,78,90])
obj1.getMarks()
obj1.display()