DOC CS FILE
DOC CS FILE
Q. Write a program to read a text file and print only the sum of all the
digits from the file.
fr = open('numbers.txt', 'r')
content = fr.readlines()
sm = 0
OUTPUT
PROGRAM 7
Finput.close()
Foutput.close()
OUTPUT
PROGRAM 8
Q. Write a program to create a function ‘STATISTICS()’ which will read a text file and
display the number of vowels, consonants, uppercase and lowercase letters in file.
def STATISTICS():
filename = input("Enter the file to check with proper extension: ").strip()
fr = open(filename, "r")
cons = set()
text = fr.read().split()
countV = 0
countC = 0
for letter in text:
if letter.isalpha():
if letter in "AEIOUaeiou":
countV += 1
else:
countC += 1
Ucase=0
for U in text:
if U.isupper():
Ucase+=1
Lcase=0
for L in text:
if L.islower():
Lcase+=1
print("The number of Lower Case letters are: ",Lcase,"\nThe number of Upper Case
letters are: ",Ucase)
STATISTICS()
OUTPUT
PROGRAM 9
fw = open("Marks.txt", "w")
while True:
ch=input("Do you want to enter student details(Y/N)")
if ch=='Y':
roll_no=input("Enter roll number of student")
name=input("Enter name of student:")
mark=input("Enter marks of student")
fw.write(roll_no)
fw.write(name)
fw.write(mark)
print("data written successfully")
else:
break
fw.close()
OUTPUT
PROGRAM 10
import pickle
fw=open("student.dat", "wb")
while True:
ch=input("do you want to enter student details(Y/N)")
if ch=='Y':
roll_no=int(input("Enter roll number of student "))
name=input("Enter name of student ")
data=[roll_no, name]
pickle.dump(data, fw)
print("data recorded sucessfully")
else:
break
fw.close()
OUTPUT
PROGRAM 11
import csv
fw=open("student.csv", "w")
cw=csv.writer(fw)
cw.writerow(['RollNo', 'Name', 'Marks'])
for i in range(3):
print("Record of Student", (i+1))
roll=int(input("Enter roll number of student"))
name=input("Enter name of student")
marks=float(input("Enter marks of student"))
data=[roll,name,marks]
cw.writerow(data)
fw.close()
fr=open("student.csv", "r")
cr=csv.reader(fr)
for row in cr:
print(row)
fr.close()
OUTPUT
PROGRAM 12
def Factorial(num):
res=1
N=int(input("Enter a number"))
fac=Factorial(N)
OUTPUT
PROGRAM 13
Q. Write a function that takes two numbers and returns the number
that has minimum One’s digit.
def two_no(n1,n2):
rem1=n1%10
rem2=n2%10
if rem1<rem2:
return n1
elif rem1>rem2:
return n2
num1=int(input("Enter a number"))
num2=int(input("Enter another number"))
print(two_no(num1,num2))
OUTPUT
PROGRAM 14
stack=[]
c='y'
while(c=='y'):
print("1 Push")
print("2 Pop")
choice=int(input("Enter your choice"))
if (choice==1):
N=input("Enter a number")
stack.append(N)
elif (choice==2):
if (stack==[]):
print(" Stack is empty")
else:
print("Deleted element is: " , stack.pop())
else:
print("Wrong input")
c=input("Do you want to continue(y/n)")
OUTPUT
PROGRAM 15
Q. Write Sql query to find the minimum, maximum, sum and average
of the marks in a student table.
PROGRAM 16
Q. Write Sql query to find the total number of customers from each
country in the table customer(customer ID, customer name, country)
using group by.
PROGRAM 17
Sname varchar(25)
Stream varchar(10)
Percent float(4,2)
def Push(Arr):
stack = []
for num in Arr:
if num % 5 == 0:
stack.append(num)
if stack:
print("Stack elements are:")
for element in stack:
print(element)
else:
print("No elements divisible by 5 found.")
lst=input("enter list")
print(Push(lst))
OUTPUT
PROGRAM 19
JOBID
. Q 21) Consider the following tables. Write SQL commands for the
statements (i) to (v).
Table : SENDER
SenderID SenderName SenderAddress SenderCity
ND01 R Jain 2, ABC Appts New Delhi
MU02 H Sinha 12, Newtown MumbaI
MU15 S Jha 27/A, Park Street Mumbai
ND50 T Prasad 122-K, SDA New Delhi
Table :RECIPIENT
RecID SenderID RecName RecAddress RecCity
KO05 ND01 R Bajpayee 5, Central Avenue Kolkata
ND08 MU02 S Mahajan 116, A Vihar New Delhi
MU19 ND01 H Singh 2A, Andheri East Mumbai
MU32 MU15 P K Swamy B5, C S Terminus MumbaI
ND48 ND50 S Tripathi 13, B1 D, Mayur Vihar New Delhi
ii. To display name of all the students whose names starts with ‘A’
iii. To display the names of students who are getting a grade ‘C’ in
either Game or Supw
Q. Find output for SQL queries (i) to (iv), which are based on tables
TRANSPORT and TRIP.
Table : TRANSPORT
Table : TRIP
Sname varchar(25)
Percent int
OUTPUT
PROGRAM 25
mycrsr=db.cursor()