Skip to content

Latest commit

 

History

History
56 lines (53 loc) · 1.32 KB

58. Unit 5 - Lesson 2.md

File metadata and controls

56 lines (53 loc) · 1.32 KB

Self Variable

Q1.

class Student:
	
	# define init method with self , name, age, email attributes
	def __init__(self,name,age,email):
		self.name = name
		self.age = age
		self.email = email
Stud_1 = Student('SriRam', 25, 'ram@sch.com') # type: Student
Stud_2 = Student('Lakshman', 28, 'laks@sch.com')
print('Stud_1 details =', Stud_1.name, Stud_1.age, Stud_1.email)
print('Stud_2 details =', Stud_2.name, Stud_2.age, Stud_2.email)

Q2.

class Car:
	def setDetails(self, model, regno):
		self.model=model
		self.regno=regno
		# write your code here
	def getModel(self):
		return self.model
		# write your code here
	def getRegno(self):
		return self.regno
		# write your code here

Hyundai = Car()
Maruthi = Car()
mod1=input("car1 model: ")
r1=input(("car1 regno: "))
mod2=input("car2 model: ")
r2=input("car2 regno: ")
Hyundai.setDetails(mod1,r1)
Maruthi.setDetails(mod2,r2)
#Take details of the car as input from user. Write your code here

print("Hyundai car details:",Hyundai.getModel(),Hyundai.getRegno())
print("Maruthi car details:",Maruthi.getModel(),Maruthi.getRegno())

Q3.

# write your code here
class Car:
	def setDetails(self,name):
		self.name=name
	def getName(self):
		return self.name
Honda=Car()
Honda_name=input("car name: ")
Honda.setDetails(Honda_name)
print("Honda car name:",Honda.getName())

Q4. 2,3