Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Python Practical Slip 3 Answers

   Write a Python program

Slip 3  A) Write a Python program to check if a given key already exists in a dictionary. If key exists replace with another key/value pair.

Answer :

dict = {'Mon':3,'Tue':5,'Wed':6,'Thu':9}

print("The given dictionary : ",dict)

check_key = input("Enter Key to check: ")

check_value = input("Enter Value: ")

if check_key in dict:

    print(check_key,"is Present.")

    dict.pop(check_key)

    dict[check_key]=check_value

else:

    print(check_key, " is not Present.")

    dict[check_key]=check_value

    print("Updated dictionary : ",dict)

Output :

 

Slip 3  B) Write a python script to define a class student having members roll no, name, age, gender. Create a subclass called Test with member marks of 3 subjects. Create three objects of the Test class and display all the details of the student with total marks.

Answer :

class Student:

def GetStudent(self):

self.RollNo=int(input("\nEnter Student Roll No:"))

self.Name=input("Enter Student Name:")

self.Age=int(input("Enter Student Age:"))

self.Gender=input("Enter Student Gender:")

 

def PutStudent(self):

print("Student Roll No:",self.RollNo)

print("Student Name:",self.Name)

print("Student Age:",self.Age)

print("Student Gender:",self.Gender)

 

class Test(Student):

def GetMarks(self):

self.MarkMar=int(input("Enter Marks of Marathi Subject"))

self.MarkHin=int(input("Enter Marks of Hindi Subject"))

self.MarkEng=int(input("Enter Marks of Eglish Subject"))

def PutMarks(self):

print("Marathi Marks:", self.MarkMar)

print("Hindi Marks:", self.MarkHin)

print("English Marks:", self.MarkEng)

print("Total Marks:",self.MarkMar+self.MarkHin+self.MarkEng)

 

n=int(input("Enter How may students"))

lst=[]

 

for i in range(0,n):

obj=input("Enter Object Name:")

lst.append(obj)

print(lst)

 

for j in range(0,n):

lst[j]=Test()

lst[j].GetStudent()

lst[j].GetMarks()

print("\nDisplay Details of Student",j+1)

lst[j].PutStudent()

lst[j].PutMarks()

Output :

Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Python Practical Slip 3 Answers Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Python Practical Slip 3 Answers Reviewed by technical_saurabh on December 31, 2021 Rating: 5

No comments:

Powered by Blogger.