Project (15 Pages)
Project (15 Pages)
line=input("Enter a line:")
lcase=ucase=0
digit=alpha=0
for a in line:
if a.islower():
lcase+=1
elif a.isupper():
ucase+=1
elif a.isdigit():
digit+=1
if a.isalpha():
alpha+=1
print("Number of alphabets:",alpha)
print("Number of digits:",digit)
#Reversing a string.
d={}
n=int(input("How many employees?"))
for i in range(n):
nm=input("Enter the name:")
sal=int(input("Enter the salary:"))
d[nm]=sal
print("dictionary created:",d)
g=0
nm=""
for i in d:
if d[i]>g:
g=d[i]
nm=i
print("Employee with highest salary:",nm)
print("his salary:",g)
#Entering records of students.
#Also printing names of students with marks
above 75.
def cal(x,y):
return x+y,x-y,x*y,x/y,x%y
num1=int(input("Enter number 1:"))
num2=int(input("Enter number 2:"))
add,sub,mult,div,mod=cal(num1,num2)
print("Sum of given numbers:",add)
print("Subtraction of given number:",sub)
print("Product of given numbers:",mult)
print("Division of given numbers:",div)
print("Modulo of given numbers:",mod)
#Checking number entered is palindrome
#or not using function
def reverse(n):
rev=0
t=n
while (n!=0):
R=n%10
rev=rev*10+R
n=n//10
return rev
n=int(input("Enter The Number = "))
a=reverse(n)
print(a)
if (a==n):
print("It is a Palindrome Number")
else:
print("It is not a Palindrome Number")
#Checking a number is prime or not.
#Using function.
def prime(x):
count=0
for a in range(2,(x//2)):
if(x%a==0):
count+=1
x=int(input("Enter the Number: "))
c=prime(x)
print(c)
if (c==0):
print("It is a Prime Number(*=*).")
else:
print("It is not a Prime Number!!!")
#Reading and Writing in a text file.
def writefile():
n=int(input("Enter the no. of students:"))
file=open("T1.txt","w")
for i in range(n):
nm=input("Enter the name:")
file.write(nm)
file.write("\n")
file.close()
def readfile():
file=open("T1.txt","r")
s=" "
while s:
s=file.readline()
print(s,end="")
file.close()
writefile()
readfile()
#Searching number number of vowels.
#File already exist and its name is "T1.txt".
def vowels():
file=open("T1.txt","r")
s=" "
c=0
while s:
s=file.read(1)
if s in ["a","e","i","o","u"]:
c+=1
print("Number of vowels:",c)
vowels()
#Writing in a binary file.
import pickle
stu={}
stufile=open("stu.dat","wb")
ans="y"
while ans=="y":
r=int(input("Enter the rollno.:"))
nm=input("Enter the name:")
mrks=int(input("Enter the marks"))
stu["Rollno"]=r
stu["Name"]=nm
stu["Marks"]=mrks
pickle.dump(stu,stufile)
ans=input("Want to enter more records?(y/n)...")
stufile.close()
#Writing in a csv file.
import csv
fh=open("student.csv","w")
swriter=csv.writer(fh)
swriter.writerow(["Rollno.","Name","Marks"])
for i in range(3):
print("student record",(i+1))
r=int(input("Enter Rollno."))
nm=input("Enter the name:")
mrks=int(input("Enter the marks:"))
rec=[r,nm,mrks]
swriter.writerow(rec)
#Creating a 2d list and traversing it.
lst=[]
r=int(input("How many rows:"))
c=int(input("How many columns:"))
for i in range(r):
row=[]
for j in range(c):
e=int(input("Enter the element:"))
row.append(e)
lst.append(row)
print("list created:",lst)
for i in range(r):
for j in range(c):
print(a[i][j],end=" ")
print()
#Usage of push and pop in stack.
def push(stk,item):
a.append(item)
def pop(stk):
if stk==[]:
print("Underflow!!!")
else:
item=stk.pop()
stk=[]
n=int(input("How mant elements?"))
for i in range(n):
e=int(input("Enter the element:"))
stk.append(e)
print("Stack created:",stk)
item=int(input("Enter the element to be insert:"))
push(stk,item)
pop(stk)