0% found this document useful (0 votes)
3 views20 pages

Python Programs for Student Management

The document contains multiple Python programs covering various functionalities such as a Student Management System, file handling for student data, a menu-driven calculator, and algorithms for sorting, searching, and mathematical computations. Each program is designed to perform specific tasks like managing student records, calculating prime numbers, and checking for palindromes. Overall, it serves as a collection of basic programming exercises demonstrating fundamental concepts in Python.

Uploaded by

dhanshu42
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views20 pages

Python Programs for Student Management

The document contains multiple Python programs covering various functionalities such as a Student Management System, file handling for student data, a menu-driven calculator, and algorithms for sorting, searching, and mathematical computations. Each program is designed to perform specific tasks like managing student records, calculating prime numbers, and checking for palindromes. Overall, it serves as a collection of basic programming exercises demonstrating fundamental concepts in Python.

Uploaded by

dhanshu42
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Program 1: Student Management System

students = {}

def add_student():
roll = int(input("Enter roll number: "))
name = input("Enter name: ")
marks = float(input("Enter marks: "))
students[roll] = [name, marks]

def display():
for r in students:
print(r, students[r][0], students[r][1])

while True:
print("[Link] [Link] [Link]")
ch = int(input("Enter choice: "))
if ch == 1:
add_student()
elif ch == 2:
display()
else:
break
Program 2: File Handling – Student Data

f = open("[Link]", "w")
n = int(input("Enter number of students: "))

for i in range(n):
name = input("Enter name: ")
marks = input("Enter marks: ")
[Link](name + " " + marks + "\n")

[Link]()

f = open("[Link]", "r")
print([Link]())
[Link]()
Program 3: Menu Driven Calculator

def add(a,b): return a+b


def sub(a,b): return a-b
def mul(a,b): return a*b
def div(a,b): return a/b

while True:
print("[Link] [Link] [Link] [Link] [Link]")
ch=int(input("Choice: "))
if ch==5: break
a=int(input("First: "))
b=int(input("Second: "))

if ch==1: print(add(a,b))
elif ch==2: print(sub(a,b))
elif ch==3: print(mul(a,b))
elif ch==4: print(div(a,b))
Program 4: Prime Numbers in Range

start=int(input("Start: "))
end=int(input("End: "))

for num in range(start,end+1):


if num>1:
for i in range(2,num):
if num%i==0:
break
else:
print(num)
Program 5: Binary Search

lst=[10,20,30,40,50]
key=int(input("Search: "))

low=0
high=len(lst)-1

while low<=high:
mid=(low+high)//2
if lst[mid]==key:
print("Found")
break
elif key>lst[mid]:
low=mid+1
else:
high=mid-1
else:
print("Not Found")
Program 6: Bubble Sort

lst=[5,1,4,2,8]
n=len(lst)

for i in range(n):
for j in range(0,n-i-1):
if lst[j]>lst[j+1]:
lst[j],lst[j+1]=lst[j+1],lst[j]

print(lst)
Program 7: Count Vowels

s=input("Enter string: ")


count=0

for ch in s:
if [Link]() in "aeiou":
count+=1

print("Vowels:",count)
Program 8: Word Count Using File

f=open("[Link]","r")
text=[Link]()
words=[Link]()
print(len(words))
[Link]()
Program 9: Fibonacci Series

def fibonacci(n):
a,b=0,1
for i in range(n):
print(a,end=" ")
a,b=b,a+b

n=int(input("Terms: "))
fibonacci(n)
Program 10: Palindrome Check

s=input("Enter string: ")


if s==s[::-1]:
print("Palindrome")
else:
print("Not Palindrome")
Program 11: Employee Dictionary

emp={}
n=int(input("Employees: "))

for i in range(n):
name=input("Name: ")
sal=int(input("Salary: "))
emp[name]=sal

for e in emp:
print(e,emp[e])
Program 12: Count Lines Words Characters

f=open("[Link]","r")
lines=[Link]()
[Link]()

print("Lines:",len(lines))

words=0
chars=0
for line in lines:
words+=len([Link]())
chars+=len(line)

print("Words:",words)
print("Chars:",chars)
Program 13: Login System

user="admin"
pwd="1234"

u=input("Username: ")
p=input("Password: ")

if u==user and p==pwd:


print("Login Successful")
else:
print("Invalid")
Program 14: Linear Search

lst=[2,4,6,8,10]
key=int(input("Search: "))

for i in range(len(lst)):
if lst[i]==key:
print("Found at",i)
break
else:
print("Not Found")
Program 15: Sum of Digits

num=int(input("Number: "))
s=0

while num>0:
s+=num%10
num//=10

print(s)
Program 16: Armstrong Number

num=int(input("Number: "))
temp=num
s=0

while temp>0:
d=temp%10
s+=d**3
temp//=10

if s==num:
print("Armstrong")
else:
print("Not Armstrong")
Program 17: Matrix Addition

A=[[1,2],[3,4]]
B=[[5,6],[7,8]]
C=[[0,0],[0,0]]

for i in range(2):
for j in range(2):
C[i][j]=A[i][j]+B[i][j]

print(C)
Program 18: Factorial Function

def fact(n):
f=1
for i in range(1,n+1):
f*=i
return f

n=int(input("Number: "))
print(fact(n))
Program 19: Remove Duplicates

lst=[1,2,2,3,4,4,5]
new=[]

for i in lst:
if i not in new:
[Link](i)

print(new)
Program 20: Student Result Processing

name=input("Name: ")
marks=[]

for i in range(5):
[Link](int(input("Marks: ")))

total=sum(marks)
percent=total/5

print("Total:",total)
print("Percentage:",percent)

You might also like