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...
Python Program : simplist form and include comments Shopping Data by Zip Code Have you ever...
Python Program : simplist form and include comments Shopping Data by Zip Code Have you ever noticed that some stores ask you for your zip code before “ringing up” your transaction? Suppose you have been given three (3) text files (named kroger.txt, publix.txt, and ingles.txt) from popular grocery stores, containing zip codes of customers at each store. Additionally, you have been given a file named zipDirectory.txt which contains the zip code and city name (each on its own line). This...
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...
Source code with comments explaining your code in C# Program 2: Buh-RING IT! For this assignment,...
Source code with comments explaining your code in C# Program 2: Buh-RING IT! For this assignment, you’re going to simulate a text-based Role-Playing Game (RPG). Design (pseudocode) and implement (source) for a program that reads in 1) the hero’s Hit Points (HP – or health), 2) the maximum damage the hero does per attack, 3) the monster’s HP and 4) the maximum monster’s damage per attack. When the player attacks, it will pick a random number between 0 and the...
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 I don't understand this code. Can you put comments to explain the statements. Also, if...
please I don't understand this code. Can you put comments to explain the statements. Also, if there any way to rewrite this code to make it easier, that gonna help me a lot. import java.io.*; import java.util.*; public class State {    private int citi1x,citi1y; private int pop1; private int citi2x,citi2y; private int pop2; private int citi3x,citi3y; private int pop3; private int citi4x,citi4y; private int pop4; private int plantx,planty; public int getCity1X(){ return citi1x; } public int getCity1Y(){ return citi1y;...
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:...
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)
(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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT