-
Notifications
You must be signed in to change notification settings - Fork 6
/
classes and modules.py
111 lines (86 loc) · 2.37 KB
/
classes and modules.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#Q1. Circle class
'''
class Circle:
def __init__(self,r):
self.radius=r
def getArea(self):
return (3.414*self.radius*self.radius)
def getCircumference(self):
return (2*3.414*self.radius)
r=int(input("Enter radius of circle: "))
obj = Circle(r)
print("Area : ",obj.getArea())
print("Circumference : ",obj.getCircumference())
'''
################
#Q2. Student class
'''
class Student:
def __init__(self,r,rn):
self.name=n
self.roll_number=rn
def display(self):
print("Name : ",self.name)
print("Roll number : ",self.roll_number)
n=input("Enter Student's name: ")
rn=int(input("Enter Student's roll number: "))
std = Student(n,rn)
std.display()
'''
###################
#Q3. Temperature class
"""
class Temperature:
def convertFahrenheit(self):
C = int(input("Enter Temperature in Celcius : "))
F=9/5*C+32
print("Temperature in Fahrenheit : ",F)
def convertCelsius(self):
F = int(input("Enter Temperature in Fahrenheit : "))
C=5/9*(F-32)
print("Temperature in Celcius : ",C)
temp1 = Temperature()
temp1.convertFahrenheit()
temp1.convertCelsius()
"""
########################
#Q4. Movie class
'''
class Movie:
def __init__(self,n,an,yor,r):
self.name=n
self.artistname=an
self.year_of_release=yor
self.ratings=r
def display(self):
print("Movie Discription :\nName : %s\nArtist Name: %s\nYear of release: %d\nRatings: %d"%(self.name,self.artistname,self.year_of_release,self.ratings))
def update(self,n,an,yor,r):
self.name=n
self.artistname=an
self.year_of_release=yor
self.ratings=r
m= Movie("Incredibles","xyz",2004,8)
m.display()
print("Updated details :------")
m.update("Incredibles 2","xyz1",2018,9)
m.display()
#Q5. Expenditure class
class Expenditure:
salary=0
def __init__(self,s,e):
self.expenditure=e
self.savings=s
def display(self):
print("Expenditure = Rs.%d\nSavings = Rs.%d"%(self.expenditure,self.savings))
def calc_total_salary(self):
self.salary=self.expenditure+self.savings
def display_salary(self):
print("Salary = Rs.",self.salary)
e=int(input("Enter expenditure amount: "))
s=int(input("Enter savings amount: "))
emp1 = Expenditure(e,s)
emp1.display()
emp1.calc_total_salary()
emp1.display_salary()
'''
## END