Input:
|
Output:
|
2000
3000
|
Ikki sonning yig’indisi: 5000
Ikki sonning kattasi: 3000
|
Pythonda dastur kodi quyidagicha:
class sum:
def __init__(self,a,b):
self.a=a
self.b=b
def yigindi(self):
return self.a+self.b
def max(self):
return max(self.a,self.b)
natija=sum(24,14)
print("ikki sonni yig`indisi ",natija.yigindi())
print("ikki sonni kattasi",natija.max())
Ikki o'zgaruvchili sinf yarating. Kirish parametrlari bo'lgan konstruktor qo'shing. Ikktita obyekt yarating va chop eting, keyin 2-obyektni o’chiring.
-
Input:
|
Output:
|
"Rustam",101
"Orzumurod",102
|
|
Pythonda dastur kodi quyidagicha:
class Employee:
def __init__(self,name,id):
self.id = id; self.name = name;
def display (self):
print("ID: %d \nName: %s"%(self.id,self.name))
emp1 = Employee("Asadbek",101)
emp2 = Employee("Elyor",102)
Foydalanilgan adabiyotlar
1. Boynazarov I.M.,Qudratov Rustam. Ma’ruzalar matni
2.Abbosbek Ibragimov, Python asoslari,95-100 sahifalar.
Mashina nomli class yarating va yaratilgan classga mashina markasi, ishlab chiqarilgan yil, yurgan masofasi kabi parametrlar yarating.Yaratilgan sinfdan info nomli metod yarating va chop eting. Yaratgan obyektlaringiz mashina1,mashina2, mashina3 kabi nomlang.
|