Slip 15 A)
Write a Python class named Student with two attributes student_name, marks.
Modify the attribute values of the said class and print the original and
modified values of the said attributes.
Answer :
class Student:
def
Accept(self):
self.name=input("Enter
Student Name:")
self.mark=int(input("Enter
Student Total Marks:"))
def
Modify(self):
self.oldmark=self.mark
self.mark=int(input("Enter
Student New Total Marks:"))
print("Student
Name:",self.name)
print("Old
Total Mark:",self.oldmark)
print("New
Total Mark:",self.mark)
#main body
Stud1=Student()
Stud1.Accept()
Stud1.Modify()
Output :
Slip 15 B)
Write a python program to accept string and remove the characters which have
odd index values of given string using user defined function.
Answer :
def MyStr():
Str=input("Enter any String: ")
cnt=len(Str)
newStr=""
for
i in range(0,cnt):
if i%2 ==0:
newStr=newStr + Str[i]
print("New String with removed odd Index Character: ",newStr)
# Mainbody
MyStr()
Output :
No comments:
Post a Comment