Question

In: Computer Science

This is a python program. Put comments explaining the code, please. Suppose you have been tasked...

This is a python program. Put comments explaining the code, please.

Suppose you have been tasked with writing a Python program (using linked lists) to keep track of computer equipment. For each piece of equipment, we track its name, purchase date, purchase amount, and quantity on hand. Write a program that completes the following tasks:

allow the user to add a piece of equipment to the front of the list;

allow the user to update the quantity of a piece of equipment;

calculate and display (to the screen) the total value (in dollars) of ALL inventory

Solutions

Expert Solution

Please Refer to the following code:-

# Node class
class Node:
    # Constructor to initialize the node object
    def __init__(self, name, purchase_date, amount, qty):
        # contains data
        self.name = name
        self.purchase_date = purchase_date
        self.amount = amount
        self.qty = qty
        # contains next node
        self.next = None


# This class contains link list operations
class LinkedList:
    # Function to initialize head
    def __init__(self):
        # initializing head to none
        self.head = None

    def insert(self, new_data):
        # Creating object for node
        new_node = Node(*new_data)
        # Pointing next of new node to current head
        new_node.next = self.head
        # shifting head to new node
        self.head = new_node

    def update_qty(self, name, qty):
        # storing head in temp
        temp = self.head
        # looping
        while (temp):
            # checking for name
            if temp.name == name:
                # updating quantity
                temp.qty = qty
                # breaking loop
                break
            # going to next node
            temp = temp.next
        else:
            # if not found
            print("Part Does not exist")

    def calculate(self):
        # intializing sum variable
        s = 0
        # storing current head in temp
        temp = self.head
        # looping in linked list
        while (temp):
            # calculating sum
            s += int(temp.amount) * int(temp.qty)
            # going to next node
            temp = temp.next
        # returning sum
        return s

# initializing linked list object
ll = LinkedList()
# loop
while True:
    # printing menu
    print("1. Add a equipment")
    print("2. update quantity")
    print("3. Calculate value")
    print("Q. quit")
    # taking Choice input
    choice = input("Choose an option:")
    if choice == '1':
        # Taking input of necessary data
        name = input("Enter name of part:")
        date = input("Enter date of part:")
        amount = input("Enter amount:")
        qty = input("Enter Qty:")
        # inserting into linked list
        ll.insert([name, date, amount, qty])
        print("Succesfully inserted")
    elif choice == '2':
        # Taking name and quantity as input
        name = input("Enter name of part:")
        qty = input("Enter Qty:")
        # updating quantity
        ll.update_qty(name, qty)
        print("Succefully Updated")
    elif choice == '3':
        # calculating total value and printing
        print("Total value is $", ll.calculate())
    elif choice.upper() == 'Q':
        # quitting
        print("Thank You,Bye!")
        break
    else:
        # wrong choice
        print('Try Again')

==================================

Output:-

1. Add a equipment
2. update quantity
3. Calculate value
Q. quit
Choose an option:1
Enter name of part:a
Enter date of part:12/01/19
Enter amount:10
Enter Qty:4
Succesfully inserted
1. Add a equipment
2. update quantity
3. Calculate value
Q. quit
Choose an option:2
Enter name of part:a
Enter Qty:5
Succefully Updated
1. Add a equipment
2. update quantity
3. Calculate value
Q. quit
Choose an option:3
Total value is $ 50
1. Add a equipment
2. update quantity
3. Calculate value
Q. quit
Choose an option:q
Thank You,Bye!

===============================

Please Refer to the following images

===============================================

Please Upvote

===============================================


Related Solutions

JAVA Please put detailed comments as well explaining your program. I'm in a beginning programming class,...
JAVA Please put detailed comments as well explaining your program. I'm in a beginning programming class, and so please use more basic techniques such as if else statements, switch operators, and for loops if needed. http://imgur.com/a/xx9Yc Pseudocode for the main method: Print the headings             Print the directions             Prompt for the month             If the month is an integer       (Hint: Use the Scanner class hasNextInt method.)                         Input the integer for the month                         Get the...
write this program in java... don't forget to put comments. You are writing code for a...
write this program in java... don't forget to put comments. You are writing code for a calendar app, and need to determine the end time of a meeting. Write a method that takes a String for a time in H:MM or HH:MM format (the program must accept times that look like 9:21, 10:52, and 09:35) and prints the time 25 minutes later. For example, if the user enters 9:21 the method should output 9:46 and if the user enters 10:52...
JAVA PROGRAM: INCLUDE COMMENTS EXPLAINING THE CODE PLEASE Given the following information: 13-inch MacBook Air, 1.6GHz...
JAVA PROGRAM: INCLUDE COMMENTS EXPLAINING THE CODE PLEASE Given the following information: 13-inch MacBook Air, 1.6GHz dual-core Intel Core i5 processor, Turbo Boost up to 2.7GHz, Intel HD Graphics 6000, 8GB memory, 128GB PCIe-based flash storage 13-inch MacBook Air, 1.6GHz dual-core Intel Core i5 processor, Turbo Boost up to 2.7GHz, Intel HD Graphics 6000, 8GB memory, 256GB PCIe-based flash storage 15.6-inch Dell i3552, 1.6GHz Processor, Intel Pentium N3700, HD Laptop, 4 GB memory, DDR3L SDRAM, Windows 10, Black Drive 3...
Please include comments on what you are doing.   Using linked lists, write a Python program that...
Please include comments on what you are doing.   Using linked lists, write a Python program that performs the following tasks: store the records for each college found in the input file - colleges.csv - into a linked list. (File includes name and state data fields) allow the user to search the linked list for a college’s name; display a message indicating whether or not the college’s name was in the database allow the user to enter a state's name and...
Can someone please write clear and concise comments explaining what each line of code is doing...
Can someone please write clear and concise comments explaining what each line of code is doing for this program in C. I just need help tracing the program and understand what its doing. Thanks #include <stdio.h> #include<stdlib.h> #include<unistd.h> #include<sys/wait.h> int join(char *com1[], char *com2[]) {    int p[2], status;    switch (fork()) {        case -1:            perror("1st fork call in join");            exit(3);        case 0:            break;        default:...
(Python Code please) Guess the number! You will add to the program you created last week....
(Python Code please) Guess the number! You will add to the program you created last week. This week you will add quite a bit of code to your project. You will add an option for the computer to guess as well as the user to guess a number. In addition, you will add a menu system. Be sure to import random at the beginning of your code and use a comment block explaining what your program does #Guess the number...
Please write in beginner level PYTHON code! Your job is to write a Python program that...
Please write in beginner level PYTHON code! Your job is to write a Python program that asks the user to make one of two choices: destruct or construct. - If the user chooses to destruct, prompt them for an alternade, and then output the 2 words from that alternade. - If the user chooses construct, prompt them for 2 words, and then output the alternade that would have produced those words. - You must enforce that the users enter real...
Suppose you are tasked with explaining health care and the health care system in the united...
Suppose you are tasked with explaining health care and the health care system in the united states to either: a) a five year old or b) an anthropologist from another planet (who has access to a basic translator) In either case, assume the individual knows that people get sick and that resources are scarce. Everything else you must explain simply. (3pts) Your answer should include: Demand uncertainty, medical effectiveness uncertainty, Medicare, Medicaid, health insurance, hospital, doctor/provider. (7pts)
1. Please program the following in Python 3 code. 2. Please share your code. 3. Please...
1. Please program the following in Python 3 code. 2. Please share your code. 3. Please show all outputs. Instructions: Run Python code  List as Stack  and verify the following calculations; submit screen shots in a single file. Postfix Expression                Result 4 5 7 2 + - * = -16 3 4 + 2  * 7 / = 2 5 7 + 6 2 -  * = 48 4 2 3 5 1 - + * + = 18   List as Stack Code: """...
Can someone please add clear and concise comments thoroughly explaining each line of code below. Just...
Can someone please add clear and concise comments thoroughly explaining each line of code below. Just need help understanding the code, don't need to modify it. The purpose of the code is to count the frequency of words in a text file, and return the most frequent word with its count. It uses two algorithms: Algorithm 1 is based on the data structure LinkedList. It maintains a list for word frequencies. The algorithm runs by scanning every token in the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT