0% found this document useful (0 votes)
21 views

Python Programming Questions

The document defines a Student class with name, age, and cgpa attributes. It includes methods to read student details from input, initialize a student object, and display student details. The class is used to create student objects, read input for attributes, and display the stored attributes. The code is further expanded to handle multiple student objects in a list and provide menu options to display details, calculate average, and find the student with the highest cgpa.

Uploaded by

Palika Shetty
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Python Programming Questions

The document defines a Student class with name, age, and cgpa attributes. It includes methods to read student details from input, initialize a student object, and display student details. The class is used to create student objects, read input for attributes, and display the stored attributes. The code is further expanded to handle multiple student objects in a list and provide menu options to display details, calculate average, and find the student with the highest cgpa.

Uploaded by

Palika Shetty
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

In [7]:

class student:
name=""
age=0
cgpa=0.0
def readstudent(this):
this.name=input("enter name")
this.age=(int)(input("enter age"))
this.cgpa=(float)(input("enter cgpa"))
def showstudent(self):
print("name",self.name)
print("age",self.age)
print("cgpa",self.cgpa)

s1=student()
s1.readstudent()
s1.showstudent()

enter namea
enter age2
enter cgpa4.9
name a
age 2
cgpa 4.9

In [19]:

class student:
def __init__(self):
self.name=""
self.age=0
self.cgpa=0.0
def readstudent(this):
this.name=input("enter name")
this.age=(int)(input("enter age"))
this.cgpa=(float)(input("enter cgpa"))
def showstudent(self):
print("name",self.name)
print("age",self.age)
print("cgpa",self.cgpa)
s1=student()
s1.readstudent()
s1.showstudent()

enter namesam
enter age19
enter cgpa9.2
name sam
age 19
cgpa 9.2

In [22]:

class student:
name=""
age=0
cgpa=0.0
def __init__(self,n,a,c):
self.name=n
self.age=a
self.cgpa=c
def readstudent(this):
this.name=input("enter name")
this.age=(int)(input("enter age"))
this.cgpa=(float)(input("enter cgpa"))
def showstudent(self):
print("name",self.name)
print("age",self.age)
print("cgpa",self.cgpa)
s1=student("vicky",8,9.2)
#s1.readstudent()
s1.showstudent()

name vicky
age 8
cgpa 9.2

In [ ]:

In [5]:

class student:
def _init_(self):
name=""
age=0
cgpa=0.0
def readstudent(self):
self.name=input("enter name")
self.age=(int)(input("enter age"))
self.cgpa=(float)(input("enter cgpa"))
def showstudent(self):
print("name",self.name)
print("age",self.age)
print("cgpa",self.cgpa)
def start():
n=(int)(input("enter information"))
if(n>0):
readNstudent(n)
menu(n)
else:
print("no student")

def menu(n):
while(1):
print("choose an option")
print("1.display detail 2.avg 3.display topper 4.exit")
choice=(int)(input("enter your choice"))
if(choice==1):
print("info")
showNstudent(n)
elif(choice==2):
print("average")
calAvg(n)
elif(choice==3):
print("topper")
topperDetails(n)
elif(choice==4):
print("done")
break
else:
print("invalid")
break

ls=[]
def readNstudent(n):
for i in range(n):
print("enter details".format(i+1))
ls.append(student())
ls[i].readstudent()
def showNstudent(n):
for i in range(n):
print("enter details".format(i+1))
ls[i].showstudent()
def calAvg(n):
sum=0
for i in range(n):
sum+=ls[i].cgpa
print("average",sum/n)
def topperDetails(n):
topper=ls[0].cgpa
for i in range(n):
if(ls[i].cgpa>topper):
topper=ls[i].cgpa
if(topper):
for i in range(n):
if(topper==ls[i].cgpa):
ls[i].showstudent()
start()
enter information2
enter details
enter namesanjan
enter age21
enter cgpa9.5
enter details
enter namesans
enter age21
enter cgpa8.5
choose an option
1.display detail 2.avg 3.display topper 4.exit
enter your choice1
info
enter details
name sanjan
age 21
cgpa 9.5
enter details
name sans
age 21
cgpa 8.5
choose an option
1.display detail 2.avg 3.display topper 4.exit
enter your choice2
average
average 9.0
choose an option
1.display detail 2.avg 3.display topper 4.exit
enter your choice3
topper
name sanjan
age 21
cgpa 9.5
choose an option
1.display detail 2.avg 3.display topper 4.exit
enter your choice4
done

In [3]:

class employee:
empname=""
age=0
salary=0.0
def __init__(self,n,a,c):
self.empname=n
self.empage=a
self.empsalary=c
def reademp(this):
this.empname=input("enter name")
this.empage=(int)(input("enter age"))
this.empsalary=(float)(input("enter salary"))
def showemp(self):
print("name",self.empname)
print("age",self.empage)
print("salary",self.empsalary)
s1=employee("ram",45,50000)
#s1.reademp()
s1.showemp()

name ram
age 45
salary 50000

In [4]:

class employee:
def __init__(self):
empname=""
empage=0
empsalary=0.0
def reademployee(self):
self.empname=input("enter name")
self.empage=(int)(input("enter age"))
self.empsalary=(float)(input("enter salary"))
def showemployee(self):
print("name",self.empname)
print("age",self.empage)
print("cgpa",self.empsalary)
def start():
n=(int)(input("enter information"))
if(n>0):
readNemployee(n)
menu(n)
else:
print("no student")

def menu(n):
while(1):
print("choose an option")
print("1.display detail 2.exit")
choice=(int)(input("enter your choice"))
if(choice==1):
print("info")
showNemployee(n)
elif(choice==2):
print("done")
break
else:
print("invalid")
break

ls=[]
def readNemployee(n):
for i in range(n):
print("enter details".format(i+1))
ls.append(employee())
ls[i].reademployee()
def showNemployee(n):
for i in range(n):
print("enter details".format(i+1))
ls[i].showemployee()

start()

enter information2
enter details
enter nameram
enter age50
enter salary50000
enter details
enter namesam
enter age40
enter salary45000
choose an option
1.display detail 2.exit
enter your choice1
info
enter details
name ram
age 50
cgpa 50000.0
enter details
name sam
age 40
cgpa 45000.0
choose an option
1.display detail 2.exit
enter your choice2
done

In [2]:

class student:
''' student details with'''
def _init_(self,n,a,c):
self.name=n
self.age=a
self.cgpa=c
def readstudent(this):
this.name=input("enter name")
this.age=(int)(input("enter age"))
this.cgpa=(float)(input("enter cgpa"))
def showstudent(self):
print("name",self.name)
print("age",self.age)
print("cgpa",self.cgpa)
print("student._doc_:",student.__doc__)
print("student._name_:",student.__name__)

student._doc_: student details with


student._name_: student

In [ ]:
In [ ]:

You might also like