Skip to content

Commit c28b69a

Browse files
Car Sale Customer -- Classes Practice Problems
1 parent df701c0 commit c28b69a

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

10X/Python/Class/Car Sale Customer.py

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
'''
2+
Car Sale Customer -- Classes Practice Problems
3+
You are moving to a different country and you want to sell your car. You bought your car for 10,00,000 Rs (10 Lakhs). You are not willing to sell the car if the customers offer you less than 90% of what you paid. You have customers lined up offering you what they are willing to pay and you have to come up with the list of customers who you can sell your car to. Each customer will submit one proposal.
4+
Design a class CarSell which has 1 method.
5+
getCustomerInput -- This method should get the indices of all the customers whose proposals are greater than or equal to 90% of the car value.
6+
If all the customers are only willing to pay less than 90%, print -1
7+
8+
Input
9+
First line contains n, an integer denoting the number of customers 0<n<=100.
10+
Next n lines will contain n integer one for each of the proposals received from n customers.
11+
12+
Output
13+
m denoting the index of the prospective customers whose proposals are greater than or equal to 90% of car value.
14+
15+
Example
16+
Input:
17+
18+
3
19+
1000000
20+
100000
21+
900000
22+
Output:
23+
24+
0
25+
2
26+
First line is 3, i.e. 3 test cases.
27+
Second line contains customer at 0th index whose proposal is 10Lakhs.
28+
Third line contains customer at index 1 whose proposal is 1Lakh.
29+
Fourth line contains customer at index 2 whose proposal is 9Lakhs.
30+
As the proposals of 0th and 2nd customer are the only ones greater than or equal to 90% of the car value. We print the output as 0 and 2
31+
32+
'''
33+
# Your class should be named `CarSell`.
34+
# Your method should be named `getPromisingCustomers`
35+
# Your method should return the indices of customers who are willing to pay greater than or equal to 90% of the car value
36+
class CarSell:
37+
def __init__(self,list):
38+
self.list=list
39+
def getPromisingCustomers(self):
40+
lists=[]
41+
for i in range(len(self.list)):
42+
if self.list[i]>=900000:
43+
lists.append(i)
44+
if len(lists):
45+
return lists
46+
else:
47+
return -1
48+
49+
50+
51+
if __name__ == "__main__":
52+
num_customers = int(input())
53+
customer_proposals = []
54+
for i in range(num_customers):
55+
customer_proposals.append(int(input()))
56+
57+
car_sell = CarSell(customer_proposals)
58+
for j in car_sell.getPromisingCustomers():
59+
print(j)

0 commit comments

Comments
 (0)