cs practical
cs practical
f=open("ninja.txt","r")
lines=f.readlines()
print(lines)
word=line.split()
for x in word:
print(x+"#",end=' ')
wordseperated()
2)stack=[]
def push():
stack.append(element)
print(stack)
def pop_element():
if not stack:
print("Stack is empty!")
else:
e=stack.pop()
print("removed element:",e)
print(stack)
while True:
if choice==1:
push()
elif choice==2:
pop_element()
elif choice==3:
break
else:
stu={}
stufile=open("stu.dat","wb")
ans="y"
while ans=="y":
name=input("enter name")
stu["rollno"]=rno
stu["name"]=name
pickle.dump(stu,stufile)
stufile.close()
found=False
srch=open("stu.dat","rb")
try:
while True:
stu=pickle.load(srch)
if stu["rollno"]==search:
print(stu)
found=True
except EOFError:
if found==False:
else:
print("search successful")
srch.close()
4) import csv
def get_item_details():
items = []
while True:
if code.lower() == 'done':
break
try:
price = float(price)
except ValueError:
continue
return items
writer = csv.writer(file)
writer.writerows(items)
def main():
filename = "items.csv"
items = get_item_details()
if items:
write_to_csv(filename, items)
else:
if __name__ == "__main__":
main()
5)def counts():
f=open("poem.txt","r")
v=c=u=l=0
data=f.read()
for i in data:
if i.isalpha():
if i.isupper():
u+=1
if i.islower():
l+=1
v+=1
else:
c+=1
print("vowerls=",v)
print("consonants=",c)
print("uppercase=", u)
print("lowercase=", l)
counts()
6) import pickle
def WRITE():
for _ in range(n):
# Function to read and display all records from the binary file
def READ():
try:
print("\nEmployee Records:")
while True:
try:
except EOFError:
except FileNotFoundError:
# Main program
while True:
print("\nMenu:")
print("3. Exit")
if choice == '1':
WRITE()
READ()
break
else:
7) import csv
def WRITE():
with open("product.csv", "w", newline="") as file: # Open the file in write mode
writer = csv.writer(file)
for _ in range(n):
# Function to read and display all records from the CSV file
def READ():
try:
reader = csv.reader(file)
print("\nProduct Records:")
except FileNotFoundError:
# Main program
while True:
print("\nMenu:")
print("3. Exit")
if choice == '1':
WRITE()
READ()
break
else:
8) def POP(stack):
if not stack:
print("The stack is empty.")
else:
while stack:
# Main program
while True:
print("\nMenu:")
print("3. Exit")
if choice == '1':
PUSH(stack)
POP(stack)
break
else:
9) def PUSH(stack):
values = []
for _ in range(n):
values.append(value)
if not stack:
def POP(stack):
if not stack:
else:
while stack:
# Main program
while True:
print("\nMenu:")
print("3. Exit")
if choice == '1':
PUSH(stack)
POP(stack)
break
else: