Ryan CS Practical 2
Ryan CS Practical 2
#Roll no: 21
#Question: 7
def append():
def countDisplay():
c = 0
with open("100TEST.txt", "r") as f:
for i in f:
c += len(i)
print(i.strip())
def cases():
with open("100TEST.txt") as f:
uc = lc = di = wh = nwspc = 0
data = f.read()
for i in data:
if i.isalpha():
if i.isupper():
uc += 1
else:
lc += 1
elif i in "1234567890":
di += 1
else:
nwspc += 1
def consonantsAndVowels():
with open("100TEST.txt") as f:
data = f.read()
uc = lc = uv = lv = 0
for i in data:
if i.upper() in "AEIOU":
if i.isupper():
uv += 1
else:
lv += 1
if i.isupper():
uc += 1
else:
lc += 1
while True:
print("1. Append")
print("2. Display")
print("3. Count Chara")
if ch == 1:
append()
elif ch == 2:
countDisplay()
elif ch == 3:
cases()
elif ch == 4:
consonantsAndVowels()
elif ch == 5:
print("Program Terminated")
break
'''
1. Append
2. Display
3. Count Chara
5. exit program
2. Display
3. Count Chara
5. exit program
the highest for any player. R Ashwin, who will play his 100th
in Dharamsala, is the only one other than Muralidaran with
of 58.95 by the end of his 100th Test, both being the highest.
His 32 hundreds, however are the joint-most alongside Kane
2. Display
3. Count Chara
Number of uppercase = 19
Number of digits = 40
1. Append
2. Display
3. Count Chara
5. exit program
Enter no. of choices: 4
1. Append
2. Display
3. Count Chara
4. Count vowels and consonants
5. exit program
#Roll no: 21
#Question: 8
def display():
c = 0
with open("100TEST.txt") as f:
for i in f:
print(i.strip())
c += len(i.split())
def count():
the = an = a = 0
with open("100TEST.txt") as f:
for i in f:
for k in i.split():
if k.upper() in "AN":
an += 1
a += 1
def countVowel():
c = 0
with open("100TEST.txt") as f:
for i in f:
for k in i.split():
if k[0].upper() in "AEIOU":
c += 1
def countwordlength():
c = 0
with open("100TEST.txt") as f:
for i in f:
for k in i.split():
if len(k) <= 6:
c += 1
print("number of words with at most 6 letters:", c)
def countConsonant():
c = 0
with open("100TEST.txt") as f:
for i in f:
for k in i.split():
a = 0
for letter in k:
if letter.upper() in
"BCDFGHJKLMNPQRSTVWXYZ":
a += 1
if a >= 3:
c += 1
while True:
if ch == 1:
display()
elif ch == 2:
count()
elif ch == 3:
countVowel()
elif ch == 4:
countwordlength()
elif ch == 5:
countConsonant()
elif ch == 6:
print("Program terminated")
break
'''
1. Count number of words
6. Exit program
Enter choice: 1
Muthiah Muralidaran has the most dominant bowling record in
the highest for any player. R Ashwin, who will play his 100th
in Dharamsala, is the only one other than Muralidaran with
of 58.95 by the end of his 100th Test, both being the highest.
His 32 hundreds, however are the joint-most alongside Kane
6. Exit program
Enter choice: 2
Number of occurrences of A: 0
6. Exit program
Enter choice: 3
6. Exit program
Enter choice: 4
number of words with at most 6 letters: 88
6. Exit program
Enter choice: 5
number of words containing atleast 3 consonants: 66
Enter choice: 6
Program terminated
'''
#Name: Ryan Roshan
#Roll no: 21
#Question 9
def display():
lines = 0
with open("100TEST.txt") as f:
for i in f:
print(i.strip())
lines += 1
def countNonVowel():
c = 0
with open("100TEST.txt") as f:
for i in f:
with open("100TEST.txt") as f:
c = 1
for i in f:
c += 1
def countAlpha():
with open("100TEST.txt") as f:
c = 1
for i in f:
a = 0
for k in i:
if k.isalpha():
a += 1
def countDigitsAndSpecial():
with open("100TEST.txt") as f:
c = 1
for i in f:
d = 0
sp = 0
for k in i:
if k.isnumeric():
d += 1
elif not k.isalnum():
sp += 1
while True:
if ch == 1:
display()
elif ch == 2:
countNonVowel()
elif ch == 3:
countWords()
elif ch == 4:
countAlpha()
elif ch == 5:
countDigitsAndSpecial()
elif ch == 6:
print("Program Terminated")
break
'''
6. Exit program
Enter choice: 1
the highest for any player. R Ashwin, who will play his 100th
of 58.95 by the end of his 100th Test, both being the highest.
6. Exit program
Enter choice: 2
6. Exit program
Enter choice: 3
Enter choice: 4
Enter choice: 5
Enter choice: 6
Program Terminated
'''
#Name: Ryan Roshan
#Roll no: 21
#Question 10
import csv
def append():
with open("TEACHER.CSV", "a", newline="") as f:
writer = csv.writer(f)
for i in range(2):
def display():
records = 0
with open("TEACHER.CSV") as f:
reader = csv.reader(f)
for i in reader:
print(i)
records += 1
print("Number of records in file:", records)
def search():
code = int(input("Enter code to be searched: "))
found = False
with open("TEACHER.CSV") as f:
reader = csv.reader(f)
for i in reader:
if int(i[0]) == code:
print(i)
found = True
if not found:
def searchSub():
with open("TEACHER.CSV") as f:
reader = csv.reader(f)
for i in reader:
if i[2] in subs:
print(i)
c += 1
if c:
while True:
print("5. exit")
if ch == 1:
append()
elif ch == 2:
display()
elif ch == 3:
search()
elif ch == 4:
searchSub()
elif ch == 5:
print("Program Terminated")
break
'''
1. Append 2 records
Enter choice: 1
Enter choice: 2
Enter choice: 3
1. Append 2 records
5. exit
Enter choice: 4
['1001', 'ADITI JAIN', 'PHYS', 'HOD', '20']
1. Append 2 records
5. exit
Enter choice: 5
Program Terminated
'''
#Name: Ryan Roshan
#Roll no: 21
#Question 11
import csv
def searchDesig():
desigs = ["TGT", "PGT"]
c = 0
with open("TEACHER.CSV") as f:
reader = csv.reader(f)
for i in reader:
if i[3] in desigs:
print(i)
c += 1
if c:
print("Number of TGT or PGT teachers:", c)
else:
def searchSubNOP():
c = 0
with open("TEACHER.CSV") as f:
reader = csv.reader(f)
for i in reader:
c += 1
if c:
def update():
f1 = open("TEACHER.CSV", "r")
reader = csv.reader(f1)
c = 0
l = []
for k in reader:
i = list(k)
i[4] = int(i[4])
if i[3] == "PRT":
i[4] += 3
c += 1
l.append(i)
f1.close()
writer.writerows(l)
f2.close()
def delete():
f1 = open("TEACHER.CSV")
reader = csv.reader(f1)
deleted = []
deleted.append(row)
f1.close()
writer = csv.writer(f2)
writer.writerow(row)
f2.close()
while True:
print("5. Exit")
if ch == 1:
searchDesig()
elif ch == 2:
searchSubNOP()
elif ch == 3:
update()
elif ch == 4:
delete()
elif ch == 5:
print("Program Terminated")
break
'''
5. Exit
Enter choice: 1
2. Search by subject
Enter choice: 2
5. Exit
Enter choice: 3
2 records updated
2. Search by subject
3. Update a record by increasing NOP of every PRT
Enter choice: 4
5. Exit
Enter choice: 5
Program Terminated
'''
#Name: Ryan Roshan
#Roll no: 21
#Question 12
import csv
import os
def searchTeacher():
f = open('TEACHER.CSV', 'r')
reader = csv.reader(f)
for row in reader:
if row[1] == name:
f.close()
return
f.close()
print("Teacher not found.")
def displayMathTgt():
count = 0
f = open('TEACHER.CSV', 'r')
reader = csv.reader(f)
count += 1
f.close()
f = open('TEACHER.CSV', 'r')
reader = csv.reader(f)
writer = csv.writer(f2)
if row[3] == 'TGT':
row[4] = str(int(row[4]) + 2)
writer.writerow(row)
f.close()
f2.close()
os.remove('TEACHER.CSV')
os.rename('temp.csv', 'TEACHER.CSV')
def deleteHod():
f = open('TEACHER.CSV', 'r')
writer = csv.writer(f2)
writer.writerow(row)
f.close()
f2.close()
os.remove('TEACHER.CSV')
os.rename('temp.csv', 'TEACHER.CSV')
print("5. Exit")
if ch == '1':
searchTeacher()
elif ch == '2':
displayMathTgt()
elif ch == '3':
updateNop()
elif ch == '4':
deleteHod()
elif ch == '5':
break
'''
2. Search by subject
3. Update a record by increasing NOP of every PRT
5. Exit
Enter choice: 1
['1002', 'ARUN GARG', 'PHYS', 'PGT', '24']
2. Search by subject
Enter choice: 2
5. Exit
Enter choice: 3
2 records updated
2. Search by subject
3. Update a record by increasing NOP of every PRT
Enter choice: 4
5. Exit
Enter choice: 4
2. Search by subject
3. Update a record by increasing NOP of every PRT
5. Exit
Enter choice: 5
Program Terminated
'''