Friday, 12 February 2021

Practical No. 19: Write a menu driven program which insert delete and display the details of a Club with cid, cname and city using stack.

 

'''

Practical No. 19: Write a menu driven program which insert delete and display the

details of a Club with cid, cname and city using stack.

'''

Club= []

c='y'

while (c=="y" or c=="Y"):

    print("1: Add Club Details: ")

    print("2: Delete Club Details: ")

    print("3: Display Club Details: ")

    choice = int(input("Enter choice: "))

    if (choice == 1):

      cid = int(input("Enter Club Id: "))

      cname = input("Enter Club Name: ")

      city = input("Enter Club City: ")

      clu = (cid,cname,city)

      Club.append(clu)

    elif (choice==2):

      if(Club == []):

         print(" Stack Empty ")

      else:

         print("Delete Element is : ", Club.pop())

    elif (choice == 3):

      L = len(Club)

      while (L>0):

       print(Club[L-1])

       L=L-1

    else:

         print("Wrong Input")

    c= input("Do you want to continue? Press 'y' to continue:")

         

      






Practical no-18: - Write a menu driven program which insert, delete and display the details of a product such as pid, pname and price using Stack.

 '''

Practical no-18: -  Write a menu driven program which insert, delete and display

the details of a product such as pid, pname and price using Stack.

'''

Product=[ ]

c="y"

while(c=="y" or c=="Y"):

       print("1: Insert Product Details: ")

       print("2: Delete Product Details: ")

       print("3: Display Product Details: ")

       choice=int(input("Enter Your Choice: "))

       if(choice==1):

              pid=int(input("Enter Product Id: "))

              pname=input("Enter Product Name: ")

              price=float(input("Enter Product Price: "))

              Prd=(pid,pname,price)

              Product.append(Prd)

       elif(choice==2):

             if(Product==[ ]):

                print("Stack Empty")

             else:

                    print("Deleted Product is: ",Product.pop())

       elif(choice==3):

              L=len(Product)

              while(L>0):

                     print(Product[L-1])

                     L=L-1

       else:

              print("Wrong input")

       c=input("Do you want to continue?, Press 'y' to continue: ")

       









Practical No.17: Write a menu driven program which insert , deleite and display the details of a movie as mid,mname and rating using stack.


'''

Practical No.17: Write a menu driven program which insert , deleite and display the details of a movie as mid,mname and rating using stack.

'''


Movie=[]

c='y'

while(c=='y' or 'Y'):

    print("1:Add Movie Details:")

    print("2:Delete Movie Details:")

    print("3:Display Movie Details:")

    choice=int(input("Enter Your Choice:"))

    if(Choice==1):

        mid=int(input("Enter Movie id: "))

        mname=input("Enter Movie Name: ")

        rating=float(input("Enter Movie Rating: "))

        mov= (mid,mname,rating)

        movie.append(mov)

    elif(Choice==2):

        if(Moivie==[]):

            print("stack empty")

        else:

            print("Deleted element is: "movie.pop())

    elif(Choice==3):

        L=len(movie)

        while(L>0):

            print(movie[L-1])

            L=L-1

    else:

        print("wrong input")

        c=input("Doyou want to continue? press 'y' to continue: ")





 


Practical No. 16: Write a menu driven program which insert, delete and display the details of a student such as roll_no,sname and course using stack.

 

'''

Practical No. 16: Write a menu driven program which insert, delete and display the

details of a student such as roll_no,sname and course using stack.

'''

Student=[]

c='y'

while(c=='y' or c=='Y'):

    print("1 : Add Student Details : ")

    print("2 : Delete Student Details : ")

    print("3 : Display Student Details : ")

    choice=int(input("Enter Your Choice: "))

    if(choice==1):

          roll_no=int(input("Enter Student Roll no: "))

          sname=input("Enter Student Name: ")

          course=input("Enter Student Course: ")

          stu=(roll_no, sname, course)

          Student.append(stu)

    elif(choice==2):

          if(Student==[]):

                 print("Stack Empty")

          else:

                 print("Deleted Element is : ", Student.pop())

    elif(choice==3):

          L=len(Student)

          while(L>0):

                 print(Student[L-1])

                 L=L-1

    else:

          print("wrong input")

    c=input("Do you want to continue ? press 'y' to continue; ")                     













Practical No. 15: - Write a menu driven program which insert, delete and display the details of a book such as book_id, book_name and price using Stack.

 '''

Practical no. 15: Write a manu driven program which insert, delete and display

the deletails of a book such as book_id, book_name and price using stack.

'''

Book=[]

c='y'

while(c=='y' or c=='Y'):

    print("1: Add Book Details: ")

    print("2: Delete Book Details: ")

    print("3: Display Book Details: ")

    choice=int(input("Enter Your Choice: "))

    if(choice==1):

        book_id=int(input("Enter Book Id: "))

        book_name=input("Enter Book Name: ")

        price=float(input("Enter Book Price: "))

        B=(book_id,book_name,price)

        Book.append(B)

    elif(choice==2):

        if(Book==[]):

            print("Stack Empty")

        else:

            print("Deleted element is: ",Book.pop())

    elif(choice==3):

        L=len(Book)

        while(L>0):

            print(Book [L-1])

            L=L-1

    else:

        print("Wrong Input")

    c=input("Do you want to continue? press 'y' to continue: ")    

        

            

 


                             

                

              



                 


    



Practical No: 14: - Write a menu driven program which insert, delete and display the details of an employee such as eid, ename and salary using Stack.








'''
Practical No. 14: Write a menu driven program which insert, delete and display
the details of an employee such as eid, ename and salary using Stack.
'''

Employee=[]
c='y'
while(c=="y" or c=="Y"):
    print("1: Add Employee Detail: ")
    print("2: Delete Employee Detail: ")
    print("3: Display Employee Detail: ")
    choice=int(input("Enter your choice: "))
    if(choice==1):
        eid=int(input("Enter Employee Id: "))
        ename=input("Enter Employee Name: ")
        salary=float(input("Enter Employee Salary: "))
        emp=(eid,ename,salary)
        Employee.append(emp)
    elif(choice==2):
        if(Employee==[]):
            print("Stack Empty")
        else:
            print("Deleted element is: ",Employee.pop())
    elif(choice==3):
        L=len(Employee)
        while(L>0):
            print(Employee[L-1])
            L=L-1
    else:
        print("Wrong Input")
    c=input("Do you want to continue? Press 'y' to Continue: ")





Thursday, 11 February 2021

Python for, while loop, pass, break, continue

 a=1

while a<=5:

    print(a)

    a=a+1



for i in range(1,6):

    print(i)



print("**********")

n=int(input("Enter a number: "))

sum=0

while n>0:

    r=n%10

    n=n//10

    sum=sum+r


print("Sum of digits =",sum)


print("**********")

a=5

while a>0:

    print(a)

    a=a-1


print("**********")


a=1

while a<=10:

    if(a%2==0):

        print(a,"is even")

    else:

        print(a,"is odd")

    a=a+1




print("Hello")

#for i in range(10):

#while True:

#if True:

for i in range(10):

    pass

print(i)

print("************")

for i in [1,2,3,4,5]:

    if(i==4):

        pass

        print("This is a pass block")

    print(i)

print("************")

for i in range(5):

    print("i=",end="")

    pass

    print(i)


print("************")

for i in range(5):

    print("i=",i)

    if i==3:

        break


print("************")

for i in range(5):

    if i==3:

        break

    print("i=",i)


print("************")

for i in range(5):

    if i==3:

        continue

    print("i=",i)


print("************")

for i in range(5):

    if i==3:

        continue

        print("i=",i)

print("************")

for i in range(5):

    if i==3:

        print("i=",i)

        continue

    

print("************")

for i in range(5):

    if i==3:

        print("i=",i)

        continue

    print(i)




print("***********")
for a in range(1,6):
    for i in range(1,6):
        print(i,end="\t")
    print()

print("***********")
for a in range(1,6):
    for i in range(1,6):
        print(a,end="\t")
    print()

print("***********")

for a in range(1,6):
    for i in range(1,a+1):
        print(i,end="\t")
    print()

print("***********")

for a in range(1,6):
    for i in range(5,0,-1):
        print(i,end="\t")
    print()

print("***********")

for a in range(5,0,-1):
    for i in range(1,a+1):
        print(a,end="\t")
    print()


print("***********")
a=1
while a<=5:
    print(a)
    a=a+1




Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb.py
1
2
3
4
5
>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb.py
1
2
3
4
5
0
1
2
3
4
>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb.py
1
2
3
4
5
1
2
3
4
5
>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb.py
1
2
3
4
5
1
2
3
4
5
**********
Enter a number456
Sum of digits = 15
>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb.py
1
2
3
4
5
1
2
3
4
5
**********
Enter a number: 345
Sum of digits = 12
**********
6
5
4
3
2
1
>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb.py
1
2
3
4
5
1
2
3
4
5
**********
Enter a number: 444
Sum of digits = 12
**********
5
4
3
2
1
>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb.py
1
2
3
4
5
1
2
3
4
5
**********
Enter a number: 123
Sum of digits = 6
**********
5
4
3
2
1
**********
1 is odd
2 is even
3 is odd
4 is even
5 is odd
6 is even
7 is odd
8 is even
9 is odd
10 is even
>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb_1.py
Hello
>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb_1.py
Hello
>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb_1.py
Hello
9
>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb_1.py
Hello
9
************
1
2
3
This is a pass block
4
5
>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb_1.py
Hello
9
************
1
2
3
This is a pass block
4
5
************
i=0
i=1
i=2
i=3
i=4
>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb_1.py
Hello
9
************
1
2
3
This is a pass block
4
5
************
i=0
i=1
i=2
i=3
i=4
************
i= 0
i= 1
i= 2
i= 3
i= 4
>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb_1.py
Hello
9
************
1
2
3
This is a pass block
4
5
************
i=0
i=1
i=2
i=3
i=4
************
i= 0
i= 1
i= 2
i= 3
>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb_1.py
Hello
9
************
1
2
3
This is a pass block
4
5
************
i=0
i=1
i=2
i=3
i=4
************
i= 0
i= 1
i= 2
i= 3
************
i= 0
i= 1
i= 2
>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb_1.py
Hello
9
************
1
2
3
This is a pass block
4
5
************
i=0
i=1
i=2
i=3
i=4
************
i= 0
i= 1
i= 2
i= 3
************
i= 0
i= 1
i= 2
************
i= 0
i= 1
i= 2
i= 4
>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb_1.py
Hello
9
************
1
2
3
This is a pass block
4
5
************
i=0
i=1
i=2
i=3
i=4
************
i= 0
i= 1
i= 2
i= 3
************
i= 0
i= 1
i= 2
************
i= 0
i= 1
i= 2
i= 4
************
>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb_1.py
Hello
9
************
1
2
3
This is a pass block
4
5
************
i=0
i=1
i=2
i=3
i=4
************
i= 0
i= 1
i= 2
i= 3
************
i= 0
i= 1
i= 2
************
i= 0
i= 1
i= 2
i= 4
************
************
i= 3
>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb_1.py
Hello
9
************
1
2
3
This is a pass block
4
5
************
i=0
i=1
i=2
i=3
i=4
************
i= 0
i= 1
i= 2
i= 3
************
i= 0
i= 1
i= 2
************
i= 0
i= 1
i= 2
i= 4
************
************
i= 3
************
0
1
2
i= 3
4
>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb_2.py
0 1 2 3 4
>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb_2.py
1 2 3 4 5
>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb_2.py
1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb_2.py
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb_2.py
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb_2.py
***********
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
***********





>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb_2.py
***********
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
***********
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5
>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb_2.py
***********
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
***********
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5
***********
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb_2.py
***********
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
***********
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5
***********
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
***********
6 5 4 3 2 1
>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb_2.py
***********
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
***********
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5
***********
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
***********
5 4 3 2 1
>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb_2.py
***********
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
***********
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5
***********
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
***********
5 4 3 2 1
5 4 3 2 1
5 4 3 2 1
5 4 3 2 1
5 4 3 2 1
>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb_2.py
***********
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
***********
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5
***********
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
***********
5 4 3 2 1
5 4 3 2 1
5 4 3 2 1
5 4 3 2 1
5 4 3 2 1
***********
5 5 5 5 5
4 4 4 4 4
3 3 3 3 3
2 2 2 2 2
1 1 1 1 1
>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb_2.py
***********
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
***********
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5
***********
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
***********
5 4 3 2 1
5 4 3 2 1
5 4 3 2 1
5 4 3 2 1
5 4 3 2 1
***********
5 5 5 5 5
4 4 4 4 4
3 3 3 3 3
2 2 2 2 2
1 1 1 1 1
>>> 
= RESTART: C:/Users/S P SHARMA/AppData/Local/Programs/Python/Python38-32/11feb_2.py
***********
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
***********
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5
***********
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
***********
5 4 3 2 1
5 4 3 2 1
5 4 3 2 1
5 4 3 2 1
5 4 3 2 1
***********
5 5 5 5 5
4 4 4 4
3 3 3
2 2
1
>>> A=[1,2,3]
>>> A.append(4)
>>> A
[1, 2, 3, 4]
>>> A.append([5,6,7])
>>> A
[1, 2, 3, 4, [5, 6, 7]]
>>> A.append(5,6,7)
Traceback (most recent call last):
  File "<pyshell#5>", line 1, in <module>
    A.append(5,6,7)
TypeError: append() takes exactly one argument (3 given)
>>> A+[5,6,7]
[1, 2, 3, 4, [5, 6, 7], 5, 6, 7]
>>> A
[1, 2, 3, 4, [5, 6, 7]]
>>> A=A+[5,6,7]
>>> A
[1, 2, 3, 4, [5, 6, 7], 5, 6, 7]
>>> A=["Hello"]
>>> A
['Hello']
>>> A.append("India")
>>> A
['Hello', 'India']
>>> len(A)
2
>>> A=[1,2,3,4,5]
>>> A
[1, 2, 3, 4, 5]
>>> A.insert(3,"Hello")
>>> A
[1, 2, 3, 'Hello', 4, 5]
>>> A=[9,8,7,6,5]
>>> A.append(4)
>>> A.insert(2,10)
>>> A
[9, 8, 10, 7, 6, 5, 4]
>>> len(A)
7
>>> A.index(10)
2
>>> A.index(5)
5
>>> A.index(7)
3
>>> max(A)
10
>>> min(A)
4
>>> A.insert(4,8)
>>> A
[9, 8, 10, 7, 8, 6, 5, 4]
>>> A.count(8)
2
>>> A.count(10)
1
>>> A.remove(10)
>>> A
[9, 8, 7, 8, 6, 5, 4]
>>> A.reverse()
>>> A
[4, 5, 6, 8, 7, 8, 9]
>>> None
>>> print(None)
None
>>> print(5)
5
>>> None == None
True
>>> A=[1,2,3]
>>> A
[1, 2, 3]
>>> A=(1,2,3)
>>> A
(1, 2, 3)
>>> A[0]
1
>>> A[1]
2
>>> A[2]
3
>>> A[1]=5
Traceback (most recent call last):
  File "<pyshell#48>", line 1, in <module>
    A[1]=5
TypeError: 'tuple' object does not support item assignment
>>> A=1,2,3
>>> A
(1, 2, 3)
>>> a,b,c=1,2,3
>>> a
1
>>> b
2
>>> c
3
>>> a,b,c
(1, 2, 3)
>>> a, b, c=1,2,3
>>> a, b, c=5,6,7
>>> a
5
>>> b
6
>>> c
7
>>> a,b,c
(5, 6, 7)
>>> type(a)
<class 'int'>
>>> type(a,b,c)
Traceback (most recent call last):
  File "<pyshell#63>", line 1, in <module>
    type(a,b,c)
TypeError: type.__new__() argument 1 must be str, not int
>>> C=a,b,c
>>> C
(5, 6, 7)
>>> type(C)
<class 'tuple'>
>>> K=[]
>>> k
Traceback (most recent call last):
  File "<pyshell#68>", line 1, in <module>
    k
NameError: name 'k' is not defined
>>> K
[]
>>> T=()
>>> T
()
>>> T=5,
>>> T
(5,)
>>> type(T)
<class 'tuple'>
>>> T1=5
>>> type(T1)
<class 'int'>
>>> T2=(5,)
>>> type(T2)
<class 'tuple'>
>>> T3=(5)
>>> T3
5
>>> T=(1,(1,2,3))
>>> T[1]
(1, 2, 3)
>>> T[1][1]
2
>>> T[3][1]
Traceback (most recent call last):
  File "<pyshell#84>", line 1, in <module>
    T[3][1]
IndexError: tuple index out of range
>>> T[1,1]
Traceback (most recent call last):
  File "<pyshell#85>", line 1, in <module>
    T[1,1]
TypeError: tuple indices must be integers or slices, not tuple
>>> T=(1,4,9,16,25)
>>> T[:]
(1, 4, 9, 16, 25)
>>> T[:4]
(1, 4, 9, 16)
>>> max(T)
25
>>> min(T)
1
>>> len(T)
5
>>> T.append(36)
Traceback (most recent call last):
  File "<pyshell#92>", line 1, in <module>
    T.append(36)
AttributeError: 'tuple' object has no attribute 'append'
>>> T.insert(2,4)
Traceback (most recent call last):
  File "<pyshell#93>", line 1, in <module>
    T.insert(2,4)
AttributeError: 'tuple' object has no attribute 'insert'
>>> T.count(4)
1
>>> T.count(2)
0
>>> "Hello".lower()
'hello'
>>> "Hello".upper()
'HELLO'
>>> S="Hello"
>>> S.lower()
'hello'
>>> S.upper()
'HELLO'
>>> S[0]
'H'
>>> S[1:3]
'el'
>>> S[::-1]
'olleH'
>>> 

Monday, 8 February 2021

Practical No: 11: - Create a binary file with 10 random numbers from 1 to 40 and print those numbers.

'''Practical No. 11: Create a binary file with 10 random numbers from 1 to 40 and print

those numbers.'''


import pickle,random

N=[]

f=open("sps.txt","wb")

for i in range(10):

    N.append(random.randint(1,40))

pickle.dump(N,f)

f.close()

print("File Created:")

print("Content of File:")

f=open("sps.txt","rb")

data=pickle.load(f)

for i in data:

    print(i)

f.close()





 





Practical No: 13: WAP in Python to read a CSV file.

 


'''

Practical No. 13: WAP in Python to read a CSV file.

'''

import csv

f=open("student.csv","r")

cr=csv.reader(f)


print("Content of CSV File: ")

for r in cr:

    print(r)

    

f.close()







Practical No.: 12 : - Write a program in Python to create a CSV file with the details of 5 students.

 

'''

Practical No. 12: Write a program in Python to create a CSV file with the details

of 5 students(Rollno, Name, Marks).

'''

import csv

f=open("student.csv","w",newline='')

cw=csv.writer(f)

cw.writerow(['Rollno','Name','Marks'])

for i in range(5):

    print("Student Record of ",(i+1))

    rollno=int(input("Enter Roll No. : "))

    name=input("Enter Name: ")

    marks=float(input("Enter Marks: "))

    sr=[rollno,name,marks]

    cw.writerow(sr)

f.close()

print("File Created Successfully")