In: Computer Science
I have an unexpected indent with my python code. please find out whats wrong with my code and run it to show that it works
here is the code :
def main(): lis = inputData() customerType = convertAcct2String(lis[0]) bushCost = getBushCost(lis[0],int(lis[1],10)) flowerCost = getFlowerBedCost(int(lis[2],10),int(lis[3],10)) fertiCost = getFertilCost(int(lis[4],10)) totalCost = calculateBill(bushCost,fertiCost,flowerCost) printReciept(customerType,totalCost,bushCost,fertiCost,flowerCost) def inputData(): account, number_of_bushes,flower_bed_length,flower_bed_width,lawn_square_footage = input("Please enter values").split() return [account, number_of_bushes,flower_bed_length,flower_bed_width,lawn_square_footage] def convertAcct2String(accountType): if accountType== "P": return "Preferred" elif accountType == "R": return "Regular" elif accountType == "N": return "New" def getBushCost(accountType,number_of_bushes): if accountType== "P" and number_of_bushes > 5: return (number_of_bushes-5)*10 elif accountType== "P" and number_of_bushes < 5: return 0 elif accountType == "R": return number_of_bushes*10 elif accountType == "N": return number_of_bushes*10*.8 def getFlowerBedCost(flower_bed_length,flower_bed_width): return flower_bed_width*flower_bed_length*2 def getFertilCost(lawn_square_footage): if lawn_square_footage == 0: return 0 num_bags = lawn_square_footage/5000 + 1 return (num_bags*11) def calculateBill(bushCost,fertiCost,flowerCost): return bushCost + fertiCost + flowerCost def printReciept(customerType,totalCost,bushCost,fertiCost,flowerCost): print("=====Falcon Landing======") print("Account Type : {}".format(customerType)) print("Flower Bed Cost: {}".format(flowerCost)) print("Fertilizer Cost: {}".format(fertiCost)) print("Total Cost: {}".format(totalCost)) if __name__ == "__main__": main()
def main(): lis = inputData() customerType = convertAcct2String(lis[0]) bushCost = getBushCost(lis[0],int(lis[1],10)) flowerCost = getFlowerBedCost(int(lis[2],10),int(lis[3],10)) fertiCost = getFertilCost(int(lis[4],10)) totalCost = calculateBill(bushCost,fertiCost,flowerCost) printReciept(customerType,totalCost,bushCost,fertiCost,flowerCost) def inputData(): account, number_of_bushes,flower_bed_length,flower_bed_width,lawn_square_footage = input("Please enter values").split() return [account, number_of_bushes,flower_bed_length,flower_bed_width,lawn_square_footage] def convertAcct2String(accountType): if accountType== "P": return "Preferred" elif accountType == "R": return "Regular" elif accountType == "N": return "New" def getBushCost(accountType, number_of_bushes): if accountType== "P" and number_of_bushes > 5: return (number_of_bushes-5)*10 elif accountType== "P" and number_of_bushes < 5: return 0 elif accountType == "R": return number_of_bushes*10 elif accountType == "N": return number_of_bushes*10*.8 def getFlowerBedCost(flower_bed_length, flower_bed_width): return flower_bed_width*flower_bed_length*2 def getFertilCost(lawn_square_footage): if lawn_square_footage == 0: return 0 num_bags = lawn_square_footage/5000 + 1 return num_bags*11 def calculateBill(bushCost,fertiCost,flowerCost): return bushCost + fertiCost + flowerCost def printReciept(customerType,totalCost,bushCost,fertiCost,flowerCost): print("=====Falcon Landing======") print("Account Type : {}".format(customerType)) print("Flower Bed Cost: {}".format(flowerCost)) print("Fertilizer Cost: {}".format(fertiCost)) print("Total Cost: {}".format(totalCost)) if __name__ == "__main__": main() |
so the problem of indentation was in getFertilCost function, the best method to remove such error is moving the statement to the beginning of the line and then using tab to space or indent them again
use multiples of 4 number of spaces as indent (TAB is the best method)
here is the output of running program.
for any query leave a comment here ill get back to you as soon as possible :)
PLEASE DO NOT FORGET TO LEAVE A THUMBS UP! THANKS! :)