Python Programming I would like to change the program below to where the output is changed to look more like a table like this example below: Part Num Description Quantity Price Total 1001 Hammer 20 15 300 1002 locks 15 5 75 Program: - #Defining the class Invoice class Invoice(object): #Declaring the Variables part_num = ' ' part_description = ' ' quantity = 0 price = 0 #Defining the __init__ method to initialize the variables def __init__(self,part_num,part_description,quantity,price): self.part_num = part_num self.part_description = part_description self.quantity = quantity self.price = price #Defining the method that returns the entered information def display(self): return 'Part number is: ' + self.part_num + '\nPart description is: ' + self.part_description + '\nQuantity of item is: ' + str(self.quantity) + '\nPrice per item is: ' + str(self.price) #Defining the method that calculates and return the Invoice amount def calculate_invoice(self): return self.quantity*self.price #Defining the class method that ask the user to enter the details @classmethod def get_user_input(self): while 1: part_num = input("\nPlease enter the part number: ") part_description = input("Please enter the part description: ") quantity = int(input("Please enter the quantity of item: ")) price = float(input("Please enter the price of item: ")) #Checking the validation if(quantity < 0 or price <= 0): print("Invalid input! Please try again") continue else: return self(part_num,part_description,quantity,price) #Creating the object of Class and calling the class method ob = Invoice.get_user_input() #Calling the method to display the entered data print(ob.display()) #Calling the method to display the Invoice amount print('\nInvoice amount is: {:.2f}'.format(ob.calculate_invoice()))
Python
I would like to change the program below to where the output is changed to look more like a table like this example below:
Part Num Description Quantity Price Total
1001 Hammer 20 15 300
1002 locks 15 5 75
Program: -
#Defining the class Invoice
class Invoice(object):
#Declaring the Variables
part_num = ' '
part_description = ' '
quantity = 0
price = 0
#Defining the __init__ method to initialize the variables
def __init__(self,part_num,part_description,quantity,price):
self.part_num = part_num
self.part_description = part_description
self.quantity = quantity
self.price = price
#Defining the method that returns the entered information
def display(self):
return 'Part number is: ' + self.part_num + '\nPart description is: ' + self.part_description + '\nQuantity of item is: ' + str(self.quantity) + '\nPrice per item is: ' + str(self.price)
#Defining the method that calculates and return the Invoice amount
def calculate_invoice(self):
return self.quantity*self.price
#Defining the class method that ask the user to enter the details
@classmethod
def get_user_input(self):
while 1:
part_num = input("\nPlease enter the part number: ")
part_description = input("Please enter the part description: ")
quantity = int(input("Please enter the quantity of item: "))
price = float(input("Please enter the price of item: "))
#Checking the validation
if(quantity < 0 or price <= 0):
print("Invalid input! Please try again")
continue
else:
return self(part_num,part_description,quantity,price)
#Creating the object of Class and calling the class method
ob = Invoice.get_user_input()
#Calling the method to display the entered data
print(ob.display())
#Calling the method to display the Invoice amount
print('\nInvoice amount is: {:.2f}'.format(ob.calculate_invoice()))
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)