-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCH2ex2.py
68 lines (61 loc) · 1.74 KB
/
CH2ex2.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
# class Bus:
# def __init__(self,people, fare):
# self.people = people
# self.fare = fare
# def __str__(self):
# return 'this bus has ' + str(self.people)+ ' people with fare = ' + str(self.fare)
# def __lt__(self,rhs):
# return self.people * self.fare < \
# rhs.people * rhs.fare
# def people_in(self,k):
# self.people += k
# def people_out(self,k):
# self.people -= k
# if self.people < 0:
# self.people = 0
# def change_fare(self,new_fare):
# self.fare = new_fare
# b1, b2, f1, f2 = input("Enter people in Bus1, Bus2, fare Bus1, Bus2 : ").split()
#
# b1 = Bus(int(b1), int(f1))
# b2 = Bus(int(b2), int(f2))
#
# if b1.people < b2.people:
# print(b1)
# print(b2)
# else:
# print(b2)
# b1.people_in(3)
# b1.people_out(6)
# b1.change_fare(12)
# print(b1)
class Bus:
def __init__(self, people, fare):
self.people = people
self.fare = fare
def __str__(self):
return 'this bus has ' + str(self.people) \
+ ' people with fare = ' + str(self.fare)
def __lt__(self, rhs):
return self.people*self.fare < \
rhs.people*rhs.fare
def people_in(self, k):
self.people += k
def people_out(self, k):
self.people -= k
if self.people < 0:
self.people = 0
def change_fare(self, new_fare):
self.fare = new_fare
b1, b2, f1, f2 = input(
"Enter people in Bus1, Bus2, fare Bus1, Bus2 : ").split()
b1 = Bus(int(b1), int(f1))
b2 = Bus(int(b2), int(f2))
if b1 < b2:
print(b1)
else:
print(b2)
b1.people_in(3)
b1.people_out(6)
b1.change_fare(12)
print(b1)