Skip to content

Instantly share code, notes, and snippets.

@codingsnap
Created January 3, 2021 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codingsnap/0dd639b3ab5a6f39f68f56eb361fd11c to your computer and use it in GitHub Desktop.
Save codingsnap/0dd639b3ab5a6f39f68f56eb361fd11c to your computer and use it in GitHub Desktop.
# Creating the class Apartment
class Apartment:
def __init__(self, flatNumber, ownerName, billAmount):
self.flatNumber = flatNumber
self.ownerName = ownerName
self.billAmount = billAmount
# Creating the class Apartment_Demo
class Apartment_demo:
# Since the constructor function does not initialises any variable, it is optional to write.
def __init__(self):
pass
# Function to calculate the second minimum Bill Amount from the list of Apartment Object.
def getSecondMinBill(self, listOfApartments):
# Initialising the list "minimum[]" to store all the electricity amount from the Apartment Object list.
minimum = []
for i in listOfApartments:
minimum.append(i.billAmount)
# Sorting the list to easily pick up the second minimum bill amount.
minimum.sort()
# Index 0 has the least value since the list is sorted, so our result is in the first index.
return minimum[1]
# Main Program
noOfObjectsToBeCreated = int(input())
objList = []
for i in range(noOfObjectsToBeCreated):
flatNumber = int(input())
ownerName = input()
billAmount = int(input())
objList.append(Apartment(flatNumber, ownerName,billAmount))
demo = Apartment_demo()
secondMinBill = demo.getSecondMinBill(objList)
print(secondMinBill)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment