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

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...
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...
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):      ...
How would I add an automatic please fill out this info to my complete code. Something...
How would I add an automatic please fill out this info to my complete code. Something similar to this code. <!doctype html> <html> <head> <meta charset="UTF-8"> <title>Untitled Document</title> <script>    function phonenumber(inputtxt){           var phoneno = (\(\d{3}\)|\d{3})[-\s]\d{3}-\d{4};       if(inputtxt.value.match(phoneno)){        document.getElementById("yourEntry").innerHTML = document.getElementById("myphone").value;    }    //if(!inputtxt.value.match(phoneno)){        // alert("Does not Work!")        //}    } </script> </head> <body> <form name="form1" action="#"> <input type="text" name="myphone" id="myphone" value="" pattern= "(\(\d{3}\)|\d{3})[-\s]\d{3}-\d{4}" placeholder="(555) 555-1212" required /> <input...
Working with Python. I am trying to make my code go through each subject in my...
Working with Python. I am trying to make my code go through each subject in my sample size and request something about it. For example, I have my code request from the user to input a sample size N. If I said sample size was 5 for example, I want the code to ask the user the following: "Enter age of subject 1" "Enter age of subject 2" "Enter age of subject 3" "Enter age of subject 4" "Enter age...
My Javascript code isn't working (when i press calculate button) - what's wrong with it ?...
My Javascript code isn't working (when i press calculate button) - what's wrong with it ? Car Rental Enter Number of Rental Days: Select Car Type: onclick= "priceofcar = 50;"/> Compact onclick= "priceofcar = 60;"/> Economy onclick= "priceofcar = 70;"/> Intermediate Select Loss Damage Waiver onclick= "damagewaiver='yes'"/> Yes onclick= "damagewaiver='no'"/> No damagewaiver = boxDays.value * 25;} else if (damagewaiver == No) { damagewaiver = 0; }/> Select Roadside Issues Coverage: onclick= "issuescoverage='yes'"/> Yes onclick= "issuescoverage='no'"/> No issuescoverage = boxDays.value *...
This is the code I have. My problem is my output includes ", 0" at the...
This is the code I have. My problem is my output includes ", 0" at the end and I want to exclude that. // File: main.cpp /*---------- BEGIN - DO NOT EDIT CODE ----------*/ #include <iostream> #include <fstream> #include <sstream> #include <iomanip> using namespace std; using index_t = int; using num_count_t = int; using isConnected_t = bool; using sum_t = int; const int MAX_SIZE = 100; // Global variable to be used to count the recursive calls. int recursiveCount =...
I cannot get this code to run on my python compiler. It gives me an expected...
I cannot get this code to run on my python compiler. It gives me an expected an indent block message. I do not know what is going on. #ask why this is now happenning. (Create employee description) class employee: def__init__(self, name, employee_id, department, title): self.name = name self.employee_id = employee_id self.department = department self.title = title def __str__(self): return '{} , id={}, is in {} and is a {}.'.format(self.name, self.employee_id, self.department, self.title)    def main(): # Create employee list emp1...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT