Question

In: Computer Science

I have an unexpected indent with my python code. please find out whats wrong with my...

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()

Solutions

Expert Solution

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! :)


Related Solutions

What's wrong with my Python code. We have to find the regularexpression in Python My output...
What's wrong with my Python code. We have to find the regularexpression in Python My output should look like this My IP address 128. 0. 0. 1 My IP address 53. 20. 62. 201 My code ipAddresses = [] ipRegEx = re.compile(r"\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}")    result = myRegEx.find all(Search Text)    def Regular_expression(ipAddresses)       for i in ipAddresses:          print(i) ipSearchResult = ipRegEx.search(line)    if ipSearchResult != None and ipSearchResult.group() not in ipAddresses:       ipAddresses.append(ipSearchResult.group()) we have to use loop too.
hi i do not know what is wrong with my python code. this is the class:...
hi i do not know what is wrong with my python code. this is the class: class Cuboid: def __init__(self, width, length, height, colour): self.__width = width self.__length = length self.__height = height self.__colour = colour self.surface_area = (2 * (width * length) + 2 * (width * height) + 2 * (length * height)) self.volume = height * length * width def get_width(self): return self.__width def get_length(self): return self.__length def get_height(self): return self.__height def get_colour(self): return self.__colour def set_width(self,...
HI can I please know whats wrong in this 2to1 mux code in VHDL code also...
HI can I please know whats wrong in this 2to1 mux code in VHDL code also please type it out so theres no confusion thank you -- Code your design here library IEEE; use IEEE.std_logic_1164.all; -- entity declaration for testbench entity test mux2 is end test; --architecture Body declaration for 2to1 mux -- component declaration of source entity 2to1 mux component test mux2 is port ( sel : in std_logic ; --select input, A : in std_logic ; --data input...
In Python I have a code: here's my problem, and below it is my code. Below...
In Python I have a code: here's my problem, and below it is my code. Below that is the error I received. Please assist. Complete the swapCaps() function to change all lowercase letters in string to uppercase letters and all uppercase letters to lowercase letters. Anything else remains the same. Examples: swapCaps( 'Hope you are all enjoying October' ) returns 'hOPE YOU ARE ALL ENJOYING oCTOBER' swapCaps( 'i hope my caps lock does not get stuck on' ) returns 'I...
Can you please see what I have done wrong with my program code and explain, This...
Can you please see what I have done wrong with my program code and explain, This python program is a guess my number program. I can not figure out what I have done wrong. When you enter a letter into the program, its supposed to say "Numbers Only" as a response. I can not seem to figure it out.. instead of an error message. import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if...
Python I want to name my hero and my alien in my code how do I...
Python I want to name my hero and my alien in my code how do I do that: Keep in mind I don't want to change my code except to give the hero and alien a name import random class Hero:     def __init__(self,ammo,health):         self.ammo=ammo         self.health=health     def blast(self):         print("The Hero blasts an Alien!")         if self.ammo>0:             self.ammo-=1             return True         else:             print("Oh no! Hero is out of ammo.")             return False     def...
Matlab code problems I have to write a code using functions to find out if a...
Matlab code problems I have to write a code using functions to find out if a year is a leap year. I'm on the write track i feel like but I keep getting an error message and matlab isnt helping to troubleshoot. The issue is on line 30. Here is my code: function project_7_mfp() %   PROJECT_7_ABC   project_7_abc() creates a function that prompts the user %   enter a year after 1582 It then determines if it is a leap year %...
This is my code for python. I am trying to do the fourth command in the...
This is my code for python. I am trying to do the fourth command in the menu which is to add an employee to directory with a new phone number. but I keep getting error saying , "TypeError: unsupported operand type(s) for +: 'dict' and 'dict". Below is my code. What am I doing wrong? from Lab_6.Employee import * def file_to_directory(File): myDirectory={}       with open(File,'r') as f: data=f.read().split('\n')    x=(len(data)) myDirectory = {} for line in range(0,199):      ...
(Python) This is my code for printing a roster for a team. When I print to...
(Python) This is my code for printing a roster for a team. When I print to the console, it makes the first player's name show up as number 2, and it says [] (its just blank for 1). How can I fix that so the first player's name is 1, not skipping 1 and going to 2. def file_to_dictionary(rosterFile): myDictionary={} myDict=[]    with open(rosterFile,'r') as f: for line in f:    (num,first,last,position)=line.split() myDictionary[num]= myDict myDict=[first, last, position] print (myDictionary) return...
this is my code in python I am trying to open a file and then print...
this is my code in python I am trying to open a file and then print the contents on my console but when i run it nothing prints in the console def file_to_dictionary(rosterFile): myDictionary={}    with open(rosterFile,'r') as f: for line in f: myDictionary.append(line.strip()) print(myDictionary)             return myDictionary    file_to_dictionary((f"../data/Roster.txt"))      
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT