Answer to Question #229793 in Python for Lia

Question #229793

# Method: Append a new price level to the levelsList

def addLevel(self):

try:

# Let the user enter a new float value and append it to the list

...

except:

# Print and error message if the user entered invalid input

...

# Method: Remove an existing price level from the levelsList

def removeLevel(self):

try:

# Let the user enter a new float value. If found in the list, remove it from the list

...

except:

# Print and error message if the user entered invalid input

...

# Method: Set levelsList to an empty list

def removeAllLevels(self):

# Set levelsList to an empty list

...

Replace ellipsis "..." with code


1
Expert's answer
2021-08-26T04:00:15-0400
# Method: Append a new price level to the levelsList
    def addLevel(self):
         errorMsg2 = "The number entered is invalid, please enter a number greater than 0."
         try:
# Let the user enter a new float value and append it to the list
            userPrice = float(input("Enter the price level to add: "))
            self.__levelsList.append(userPrice)
         except:
# Print and error message if the user entered invalid input
            if userPrice < 0:
                print(errorMsg2)

# Method: Remove an existing price level from the levelsList
    def removeLevel(self):
        
        errorMsg2 = "The number entered is invalid, please enter a number greater than 0."
         try:
# Let the user enter a new float value and append it to the list
            userPrice = float(input("Enter the price level to add: "))
            if userPrice in self.__levelsList:
              self.__levelsList.remove(userPrice)
         except:
# Print and error message if the user entered invalid input
            if userPrice < 0:
                print(errorMsg2)

# Method: Set levelsList to an empty list
    def removeAllLevels(self):
      self.__levelsList.clear()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS