Question

YOU NEED TO MODIFY THE PROJECT INCLUDED AT THE END AND USE THE INCLUDED DRIVER TO...

YOU NEED TO MODIFY THE PROJECT INCLUDED AT THE END AND USE THE INCLUDED DRIVER TO TEST YOUR CODE TO MAKE SURE IT WORK AS EXPECTED. Thanks

USING PYTHON, complete the template below such that you will provide code to solve the following problem:

Please write and/or extend the project5 attached at the end.
You will have to do the following for this assignment:

Create and complete the methods of the PriceException class.

Create the processFile function.

Modify the main function in project5.py.


You will be creating a PriceException class that extends the Exception class with the following methods. Later, you will modify your main method to use this class. Write the following methods for the PriceException class:

A constructor that takes a message as an argument. The constructor creates this attribute, and sets it to the incoming argument. The constructor also initializes an empty list of items.

A to-string method that can be called with str(...), which returns the message of the exception.


You will write a function called processFile:

You will write a function called processFile that takes as argument a filename, and opens that file and returns its contents, as a list of strings.


Finally, modify your main:

Do not add duplicate items (same id) or shipments to the list of shipments being created. That is, each shipment-item pairing must be unique.

You may modify the classes you wrote as necessary.

Raise a PriceException (the new class you just wrote) when there is something wrong with just the price read in; otherwise, if the price is right (haha!) but the item is still wrong, continue to raise anItemException.



Testing Your Code

When you are ready, right-mouse-click to save the file as driver.py to the same directory as your project5.py. This driver already contains the tests, and will tell you which test number you're failing; look at the source code of the driver to see the details of that test. You can run the driver through the terminal with the command: python driver.py

The driver is as follows:

from project5 import *
import traceback
import subprocess

def checkEqual(shipments1,shipments2):
    #print [str(s) for s in shipments1]
    #print [str(s) for s in shipments2]
    ctr = 0
    if len(shipments1) != len(shipments2):
        return False
    while ctr < len(shipments1):
        shipment1 = shipments1[ctr]
        shipment2 = shipments2[ctr]
        if str(shipment1.getId()) != str(shipment2.getId()):
            return False
        if len(shipment1.getItems()) != len(shipment2.getItems()):
            return False
        i = 0
        while i < len(shipment1.getItems()):
            item1 = shipment1.getItems()[i]
            item2 = shipment2.getItems()[i]
            if str(item1) != str(item2):
                return False
            i = i + 1
        ctr = ctr + 1
         
    return True
         


def test1():
    item = Item('sockz',12346,'$4.44')
    return str(item) == 'sockz 12346 $4.44'
     
def test2():
    item = Item('sockz',12346,'$4.44')
    return str(item.getName()) == 'sockz'     
     
def test3():
    item = Item('sockz',12346,'$4.44')
    return str(item.getId()) == '12346'         
     
def test4():
    item = Item('sockz',12346,'$4.44')
    return str(item.getPrice()) == '$4.44'         
     
def test5():
    shipment = Shipment(55551555)
    return str(shipment) == '55551555: []'
     
def test6():
    shipment = Shipment(55551555)
    return str(shipment.getId()) == '55551555'     
     
def test7():
    shipment = Shipment(55551555)
    return shipment.getItems() == []         
     
def test8():
    item = Item('sockz',12346,'$4.44')
    shipment = Shipment(55551555)
    shipment.addItem(item)
    return str(shipment) == '55551555: [sockz 12346 $4.44]'     
     
def test9():
    item = Item('sockz',12346,'$4.44')
    shipment = Shipment(55551555)
    shipment.addItem(item)
    item = Item('shirt',33233,'$14.78')
    shipment.addItem(item)         
    return str(shipment) == '55551555: [sockz 12346 $4.44,shirt 33233 $14.78]'         
     
def test10():
    item = Item('sockz',12346,'$4.44')
    shipment = Shipment(55551555)
    shipment.addItem(item)
    result = main(['55551555\n','sockz 12346\n','$4.44\n'])
     
    return checkEqual([shipment],result)
     
def test11():
    shipments = []
    shipment = Shipment(55551555)
    item = Item('sockz',12346,'$4.44')     
    shipment.addItem(item)
    item = Item('shorts',33233,'$42.56')     
    shipment.addItem(item)         
    shipments.append(shipment)

    result = main(['55551555\n','sockz 12346\n','$4.44\n','shorts 33233\n','$42.56\n'])
     
    return checkEqual(shipments,result)     
     
def test12():
    shipments = []

    shipment = Shipment(55551555)     
    item = Item('sockz',12346,'$4.44')
    shipment.addItem(item)     
    item = Item('shorts',33233,'$42.56')     
    shipment.addItem(item)     
    shipments.append(shipment)     

    item = Item('books',12346,'$4.44')
    shipment = Shipment(66678)
    shipment.addItem(item)
    item = Item('mirror',33233,'$42.56')     
    shipment.addItem(item)             
    shipments.append(shipment)     

    shipment = Shipment(1)
    item = Item('shoez',12346,'$4.44')
    shipment.addItem(item)     
    item = Item('pencils',33233,'$42.56')     
    shipment.addItem(item)                             

    shipments.append(shipment)     

    result = main(['55551555\n','sockz 12346\n','$4.44\n','shorts 33233\n','$42.56\n','66678\n','books 12346\n','$4.44\n','mirror 33233\n','$42.56\n','necklace 33233\n','$42.56\n','1\n','shoez 12346\n','$4.44\n','pencils 33233\n','$42.56\n','eraser 33233\n','$42.56\n'])

    return checkEqual(shipments,result)     
     
def test13():
    shipments = []
    item = Item('sockz',12346,'$4.44')
    shipment = Shipment(55551555)
    shipment.addItem(item)
    item = Item('sockz',12347,'$4.44')     
    shipment.addItem(item)
    shipments.append(shipment)

    result = main(['55551555\n','sockz 12346\n','$4.44\n','sockz 12347\n','$4.44\n'])
     
    return checkEqual(shipments,result)     
     
def test14():
    result = False
    try:
        main(['55551555\n','sockz12346\n','$4.44\n','sockz 12346\n','$4.44\n'])
    except ItemException:
        result = True
     
    return result     
     
def test15():
    result = False
    try:
        main(['55551555\n','sockz 12346\n','4.44\n','sockz 12346\n','$4.44\n'])
    except PriceException:
        result = True
     
    return result     
     
def test16():
    result = False
    try:
        main(['55551555\n','sockz 12346\n','$4.447\n','sockz 12346\n','$4.44\n'])
    except PriceException:
        result = True
     
    return result         
     
def test17():
    result = False
    try:
        main(['55551555\n','sockz 12346\n','$4.44\n','sockz 12346\n','$-4.44\n'])
    except PriceException:
        result = True
     
    return result         
     
def test18():
    result = False
    try:
        main(['55551555\n','sockz 12346\n','$4.44\n','sockz 12346\n','$4.44.56\n'])
    except PriceException:
        result = True
     
    return result             
     
def test19():
    file = open("data.txt","w")
    file.write("5555155555\nSocks 12346\n$5.59\n")
    file.close()
    list = processFile("data.txt")
    return list == ["5555155555\n","Socks 12346\n","$5.59\n"]
     
def test20():
    shipments = []

    shipment = Shipment(55551555)     
    item = Item('sockz',12346,'$4.44')
    shipment.addItem(item)     
    item = Item('shorts',33233,'$42.56')     
    shipment.addItem(item)     
    shipments.append(shipment)     

    item = Item('books',12346,'$4.44')
    shipment = Shipment(66678)
    shipment.addItem(item)
    item = Item('mirror',33233,'$42.56')     
    shipment.addItem(item)     
    item = Item('necklace',33253,'$42.56')     
    shipment.addItem(item)         
    shipments.append(shipment)     

    shipment = Shipment(1)
    item = Item('sockz',12346,'$4.44')
    shipment.addItem(item)
    item = Item('pencils',33237,'$42.56')     
    shipment.addItem(item)                             
    item = Item('eraser',33233,'$42.56')     
    shipment.addItem(item)         
    shipments.append(shipment)     

    result = main(['55551555\n','sockz 12346\n','$4.44\n','shorts 33233\n','$42.56\n','66678\n','books 12346\n','$4.44\n','mirror 33233\n','$42.56\n','necklace 33253\n','$42.56\n','1\n','sockz 12346\n','$4.44\n','pencils 33237\n','$42.56\n','eraser 33233\n','$42.56\n'])

    return checkEqual(shipments,result)     
     
def test21():
    shipments = []

    shipment = Shipment(55551555)     
    item = Item('sockz',12346,'$4.44')
    shipment.addItem(item)     
    item = Item('shorts',33233,'$42.56')     
    shipment.addItem(item)     
    shipments.append(shipment)     

    item = Item('books',12346,'$4.44')
    shipment = Shipment(66678)
    shipment.addItem(item)
    item = Item('mirror',33233,'$42.56')     
    shipment.addItem(item)         
    shipments.append(shipment)     

    shipment = Shipment(1)
    item = Item('shoes',12346,'$4.44')
    shipment.addItem(item)
    item = Item('pencils',33233,'$42.56')     
    shipment.addItem(item)                                 
    shipments.append(shipment)     

    result = main(['55551555\n','sockz 12346\n','$4.44\n','shorts 33233\n','$42.56\n','66678\n','books 12346\n','$4.44\n','mirror 33233\n','$42.56\n','necklace 33233\n','$42.56\n','1\n','shoes 12346\n','$4.44\n','pencils 33233\n','$42.56\n','eraser 33233\n','$42.56\n'])

    return checkEqual(shipments,result)         
     
failed = False
ctr = 1
while ctr <= 21:
    try:
        if eval("test"+str(ctr)+"()") == True:
            print "PASSED test"+str(ctr)+"!"
        else:
            print "Please check your code for test"+str(ctr)
            failed = True
    except Exception as e:
        traceback.print_exc()
        print "Please check your code for test"+str(ctr)+", it raised an undesired exception"
        failed = True
    ctr = ctr + 1
if not failed:
    print "You PASSED ALL TESTS"
    result = subprocess.check_output("curl -k    https://cs.gmu.edu/~kdobolyi/sparc/process.php?user=sparc_JjNcihjCCN7CpKRh-sample_ass9_2-COMPLETED", shell=True)     
     
else:
    print "At least one test is not passing yet."     
    result = subprocess.check_output("curl -k    https://cs.gmu.edu/~kdobolyi/sparc/process.php?user=sparc_JjNcihjCCN7CpKRh-sample_ass9_2-PROGRESS", shell=True)
          

The following part (project5.py) is for reference only:

class Item:
   def __init__(self,name,id,price):
       self.name = name
       self.Id = id
       self.price = price
   def getName(self):
       return self.name
   def getPrice(self):
       return self.price
   def getId(self):
       return self.Id
   def __str__(self):
       return str(self.name)+ ' ' + str(self.Id)+ ' ' + str(self.price)

class Shipment:
   def __init__(self,id):
       self.id = id
       self.items = []
   def getId(self):
       return self.id
   def getItems(self):
       return self.items
   def addItem(self,item):
       self.items.append(item)
   def __str__(self):
       result = str(self.id) + ': ['
       ctr = 0
       while ctr < len(self.items):
           if ctr == len(self.items)-1:
               result += str(self.items[ctr])
           else:
               result += str(self.items[ctr]) + ','
           ctr += 1
       return result + ']'


class ItemException:
   def __init__(self,message):
       self.message = message
       self.empty_lis = []
  
   def __str__(self):
       return str(self.message)
      

class PriceException:
   def __init__(self):
       self.messages = messages
       self.empty = []
  
   def __str__(self):
       return str(self.message)

def processFile(filename):
   file = open('filename','r')
   contents = file.readlines()
   list = str(contents)
   return list


  
def main(lis):
   final = []
   ctr = 0
   #This will split up multiple shipments into lists within a list (will also leave single shipments in a list of a list)
  
   while ctr < len(lis):
       seperate_items = []
       if lis[ctr][:-1].isdigit():
           seperate_items.append(lis[ctr][:-1])
           ctr2 = ctr + 1
           while ctr2 < len(lis):
               if not lis[ctr2][:-1].isdigit():
                   seperate_items.append(lis[ctr2][:-1])
               else:
                   break
               ctr2 += 1
           final.append(seperate_items)
       ctr += 1
  
   #[['55555555', 'socks 12345', '$4.56', 'shorts 33333', '$42.56']]
   #Now I need to make the code run with the new values like it should to pass
   #This section needs to be modified to sort...
   #the name of the items by their name in alphabetical order
   #and shipments need to be sorted by their ids in numeric order (ascending).
  
   ctr3 = 0
   result = []
   while ctr3 < len(final):
       ctr4 = 1
       shipmentId = final[ctr3][ctr4-1]
       shipment = Shipment(shipmentId)
       while ctr4 < len(final[ctr3]):
           if not final[ctr3][ctr4].isdigit():
               shipitem = final[ctr3][ctr4].split(' ')[0]
               #raise an exception for there being a missing space
               #between an item and its ID
               if len(final[ctr3][ctr4].split(' ')) == 1:
                   raise ItemException(Exception)
               itemId = final[ctr3][ctr4].split(' ')[1]
               itemPrice = final[ctr3][ctr4+1]
               if itemPrice[0] != '$' or itemPrice[-3] != '.' or '-' in itemPrice or itemPrice.count('.') > 1:
                   raise ItemException(Exception)
               item = Item(shipitem, itemId, itemPrice)
               shipment.addItem(item)
           ctr4 += 2
       ctr3 += 1
       result.append(shipment)
       #result is the origonal end of the code in Project 5
       #[55555555: [socks 12345 $4.56,shorts 33333 $42.56],66678: [books 12345 $4.56,mirror 33333 $42.56,necklace 333333 $42.56],1: [shoes 12345 $4.56,pencils 33333 $42.56,eraser 33333 $42.56]]
      
   #Make a loop to sort the shipmentId in numerical order (ascending)
   new_list = []
   while result:
       minimum = result[0]
       for x in result:
           if x < minimum:
               minimum = x
       new_list.append(minimum)
       result.remove(minimum)
   #Make a loop to sort the items in alphabetical order
   alpha_list = []
   ctr5 = 0
   while new_list:
       minimum2 = new_list[ctr5][0]
       for i in new_list[ctr5]:
           if i < minimum2:
               minimum2 = i
       alpha_list.append(minimum2)
       ctr5 += 1
  
   return alpha_list

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import traceback
import subprocess

def checkEqual(shipments1,shipments2):
shipment1,shipment2;
ctr = 0
if len(shipments1) != len(shipments2):
return False
while ctr < len(shipments1):
shipment1 = shipments1[ctr]
shipment2 = shipments2[ctr]
if str(shipment1.getId()) != str(shipment2.getId()):
return False
if len(shipment1.getItems()) != len(shipment2.getItems()):
return False
i = 0
while i < len(shipment1.getItems()):
item1 = shipment1.getItems()[i]
item2 = shipment2.getItems()[i]
if str(item1) != str(item2):
return False
i = i + 1
ctr = ctr + 1

return True


def test1():
item = Item('sockz',12346,'$4.44')
return str(item) == 'sockz 12346 $4.44'

def test2():
item = Item('sockz',12346,'$4.44')
return str(item.getName()) == 'sockz'   

def test3():
item = Item('sockz',12346,'$4.44')
return str(item.getId()) == '12346'   

def test4():
item = Item('sockz',12346,'$4.44')
return str(item.getPrice()) == '$4.44'   

def test5():
shipment = Shipment(55551555)
return str(shipment) == '55551555: []'

def test6():
shipment = Shipment(55551555)
return str(shipment.getId()) == '55551555'   

def test7():
shipment = Shipment(55551555)
return shipment.getItems() == []   

def test8():
item = Item('sockz',12346,'$4.44')
shipment = Shipment(55551555)
shipment.addItem(item)
return str(shipment) == '55551555: [sockz 12346 $4.44]'   

def test9():
item = Item('sockz',12346,'$4.44')
shipment = Shipment(55551555)
shipment.addItem(item)
item = Item('shirt',33233,'$14.78')
shipment.addItem(item)   
return str(shipment) == '55551555: [sockz 12346 $4.44,shirt 33233 $14.78]'   

def test10():
item = Item('sockz',12346,'$4.44')
shipment = Shipment(55551555)
shipment.addItem(item)
result = main(['55551555\n','sockz 12346\n','$4.44\n'])

return checkEqual([shipment],result)

def test11():
shipments = []
shipment = Shipment(55551555)
item = Item('sockz',12346,'$4.44')   
shipment.addItem(item)
item = Item('shorts',33233,'$42.56')   
shipment.addItem(item)   
shipments.append(shipment)

result = main(['55551555\n','sockz 12346\n','$4.44\n','shorts 33233\n','$42.56\n'])

return checkEqual(shipments,result)   

def test12():
shipments = []

shipment = Shipment(55551555)   
item = Item('sockz',12346,'$4.44')
shipment.addItem(item)   
item = Item('shorts',33233,'$42.56')   
shipment.addItem(item)   
shipments.append(shipment)   

item = Item('books',12346,'$4.44')
shipment = Shipment(66678)
shipment.addItem(item)
item = Item('mirror',33233,'$42.56')   
shipment.addItem(item)   
shipments.append(shipment)   

shipment = Shipment(1)
item = Item('shoez',12346,'$4.44')
shipment.addItem(item)   
item = Item('pencils',33233,'$42.56')   
shipment.addItem(item)   

shipments.append(shipment)   

result = main(['55551555\n','sockz 12346\n','$4.44\n','shorts 33233\n','$42.56\n','66678\n','books 12346\n','$4.44\n','mirror 33233\n','$42.56\n','necklace 33233\n','$42.56\n','1\n','shoez 12346\n','$4.44\n','pencils 33233\n','$42.56\n','eraser 33233\n','$42.56\n'])

return checkEqual(shipments,result)   

def test13():
shipments = []
item = Item('sockz',12346,'$4.44')
shipment = Shipment(55551555)
shipment.addItem(item)
item = Item('sockz',12347,'$4.44')   
shipment.addItem(item)
shipments.append(shipment)

result = main(['55551555\n','sockz 12346\n','$4.44\n','sockz 12347\n','$4.44\n'])

return checkEqual(shipments,result)   

def test14():
result = False
try:
main(['55551555\n','sockz12346\n','$4.44\n','sockz 12346\n','$4.44\n'])
except ItemException:
result = True

return result   

def test15():
result = False
try:
main(['55551555\n','sockz 12346\n','4.44\n','sockz 12346\n','$4.44\n'])
except PriceException:
result = True

return result   

def test16():
result = False
try:
main(['55551555\n','sockz 12346\n','$4.447\n','sockz 12346\n','$4.44\n'])
except PriceException:
result = True

return result   

def test17():
result = False
try:
main(['55551555\n','sockz 12346\n','$4.44\n','sockz 12346\n','$-4.44\n'])
except PriceException:
result = True

return result   

def test18():
result = False
try:
main(['55551555\n','sockz 12346\n','$4.44\n','sockz 12346\n','$4.44.56\n'])
except PriceException:
result = True

return result   

def test19():
file = open("data.txt","w")
file.write("5555155555\nSocks 12346\n$5.59\n")
file.close()
list = processFile("data.txt")
return list == ["5555155555\n","Socks 12346\n","$5.59\n"]

def test20():
shipments = []

shipment = Shipment(55551555)   
item = Item('sockz',12346,'$4.44')
shipment.addItem(item)   
item = Item('shorts',33233,'$42.56')   
shipment.addItem(item)   
shipments.append(shipment)   

item = Item('books',12346,'$4.44')
shipment = Shipment(66678)
shipment.addItem(item)
item = Item('mirror',33233,'$42.56')   
shipment.addItem(item)   
item = Item('necklace',33253,'$42.56')   
shipment.addItem(item)   
shipments.append(shipment)   

shipment = Shipment(1)
item = Item('sockz',12346,'$4.44')
shipment.addItem(item)
item = Item('pencils',33237,'$42.56')   
shipment.addItem(item)   
item = Item('eraser',33233,'$42.56')   
shipment.addItem(item)   
shipments.append(shipment)   

result = main(['55551555\n','sockz 12346\n','$4.44\n','shorts 33233\n','$42.56\n','66678\n','books 12346\n','$4.44\n','mirror 33233\n','$42.56\n','necklace 33253\n','$42.56\n','1\n','sockz 12346\n','$4.44\n','pencils 33237\n','$42.56\n','eraser 33233\n','$42.56\n'])

return checkEqual(shipments,result)   

def test21():
shipments = []

shipment = Shipment(55551555)   
item = Item('sockz',12346,'$4.44')
shipment.addItem(item)   
item = Item('shorts',33233,'$42.56')   
shipment.addItem(item)   
shipments.append(shipment)   

item = Item('books',12346,'$4.44')
shipment = Shipment(66678)
shipment.addItem(item)
item = Item('mirror',33233,'$42.56')   
shipment.addItem(item)   
shipments.append(shipment)   

shipment = Shipment(1)
item = Item('shoes',12346,'$4.44')
shipment.addItem(item)
item = Item('pencils',33233,'$42.56')   
shipment.addItem(item)   
shipments.append(shipment)   

result = main(['55551555\n','sockz 12346\n','$4.44\n','shorts 33233\n','$42.56\n','66678\n','books 12346\n','$4.44\n','mirror 33233\n','$42.56\n','necklace 33233\n','$42.56\n','1\n','shoes 12346\n','$4.44\n','pencils 33233\n','$42.56\n','eraser 33233\n','$42.56\n'])

return checkEqual(shipments,result)   

failed = False
ctr = 1
while ctr <= 21:
try:
if eval("test"+str(ctr)+"()") == True:
print "PASSED test"+str(ctr)+"!"
else:
print "Please check your code for test"+str(ctr)
failed = True
except Exception as e:
traceback.print_exc()
print "Please check your code for test"+str(ctr)+", it raised an undesired exception"
failed = True
ctr = ctr + 1
if not failed:
print "You PASSED ALL TESTS"
result = subprocess.check_output("curl -k https://cs.gmu.edu/~kdobolyi/sparc/process.php?user=sparc_JjNcihjCCN7CpKRh-sample_ass9_2-COMPLETED", shell=True)   

else:
print "At least one test is not passing yet."   
result = subprocess.check_output("curl -k https://cs.gmu.edu/~kdobolyi/sparc/process.php?user=sparc_JjNcihjCCN7CpKRh-sample_ass9_2-PROGRESS", shell=True)
  
The following part (project5.py) is for reference only:
class Item:
def __init__(self,name,id,price):
self.name = name
self.Id = id
self.price = price
def getName(self):
return self.name
def getPrice(self):
return self.price
def getId(self):
return self.Id
def __str__(self):
return str(self.name)+ ' ' + str(self.Id)+ ' ' + str(self.price)
class Shipment:
def __init__(self,id):
self.id = id
self.items = []
def getId(self):
return self.id
def getItems(self):
return self.items
def addItem(self,item):
self.items.append(item)
def __str__(self):
result = str(self.id) + ': ['
ctr = 0
while ctr < len(self.items):
if ctr == len(self.items)-1:
result += str(self.items[ctr])
else:
result += str(self.items[ctr]) + ','
ctr += 1
return result + ']'

class ItemException:
def __init__(self,message):
self.message = message
self.empty_lis = []
  
def __str__(self):
return str(self.message)
  
class PriceException:
def __init__(self):
self.messages = messages
self.empty = []
  
def __str__(self):
return str(self.message)
def processFile(filename):
file = open('filename','r')
contents = file.readlines()
list = str(contents)
return list

  
def main(lis):
final = []
ctr = 0
  
while ctr < len(lis):
seperate_items = []
if lis[ctr][:-1].isdigit():
seperate_items.append(lis[ctr][:-1])
ctr2 = ctr + 1
while ctr2 < len(lis):
if not lis[ctr2][:-1].isdigit():
seperate_items.append(lis[ctr2][:-1])
else:
break
ctr2 += 1
final.append(seperate_items)
ctr += 1

  
ctr3 = 0
result = []
while ctr3 < len(final):
ctr4 = 1
shipmentId = final[ctr3][ctr4-1]
shipment = Shipment(shipmentId)
while ctr4 < len(final[ctr3]):
if not final[ctr3][ctr4].isdigit():
shipitem = final[ctr3][ctr4].split(' ')[0]

if len(final[ctr3][ctr4].split(' ')) == 1:
raise ItemException(Exception)
itemId = final[ctr3][ctr4].split(' ')[1]
itemPrice = final[ctr3][ctr4+1]
if itemPrice[0] != '$' or itemPrice[-3] != '.' or '-' in itemPrice or itemPrice.count('.') > 1:
raise ItemException(Exception)
item = Item(shipitem, itemId, itemPrice)
shipment.addItem(item)
ctr4 += 2
ctr3 += 1
result.append(shipment)


new_list = []
while result:
minimum = result[0]
for x in result:
if x < minimum:
minimum = x
new_list.append(minimum)
result.remove(minimum)

alpha_list = []
ctr5 = 0
while new_list:
minimum2 = new_list[ctr5][0]
for i in new_list[ctr5]:
if i < minimum2:
minimum2 = i
alpha_list.append(minimum2)
ctr5 += 1
  return alpha_list

Add a comment
Know the answer?
Add Answer to:
YOU NEED TO MODIFY THE PROJECT INCLUDED AT THE END AND USE THE INCLUDED DRIVER TO...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PYTHON. Continues off another code. I don't understand this. Someone please help! Comment the lines please...

    PYTHON. Continues off another code. I don't understand this. Someone please help! Comment the lines please so I can understand LinkedList ADT: class myLinkedList:     def __init__(self):         self.__head = None         self.__tail = None         self.__size = 0     def insert(self, i, data):         if self.isEmpty():             self.__head = listNode(data)             self.__tail = self.__head         elif i <= 0:             self.__head = listNode(data, self.__head)         elif i >= self.__size:             self.__tail.setNext(listNode(data))             self.__tail = self.__tail.getNext()         else:             current = self.__getIthNode(i - 1)             current.setNext(listNode(data,...

  • PYTHON. Continues off another code(other code is below). I don't understand this. Someone please help! Comment...

    PYTHON. Continues off another code(other code is below). I don't understand this. Someone please help! Comment the lines please so I can understand. There are short and med files lengths for each the list of names/ids and then search id file. These are the input files: https://codeshare.io/aVQd46 https://codeshare.io/5M3XnR https://codeshare.io/2W684E https://codeshare.io/5RJwZ4 LinkedList ADT to store student records(code is below). Using LinkedList ADT instead of the Python List. You will need to use the Student ADT(code is below) Imports the Student class...

  • # Problem 3 def printexp(tree): sVal = "" if tree: sVal = '(' + printexp(tree.getLeftChild()) sVal = sV...

    # Problem 3 def printexp(tree): sVal = "" if tree: sVal = '(' + printexp(tree.getLeftChild()) sVal = sVal + str(tree.getRootVal()) sVal = sVal + printexp(tree.getRightChild())+')' return sVal #### Functions and classes to help with Homework 6 #### You should not make any changes to the functions and classes in this file, #### but you should understand what they do and how they work. import sys ### This function will be re-defined in hw6.py. However, it is needed for ExpTree, ###...

  • Python3 programming help needed LAB*: Program: Online shopping cart (continued) Need the below code edited to...

    Python3 programming help needed LAB*: Program: Online shopping cart (continued) Need the below code edited to run properly for the lab.. class ItemPurchase:     def __init__(self, nameitem='none', item_prc=0, item_quntity=0, item_descrp = 'none'):         self.nameitem = nameitem         self.item_prc = item_prc         self.item_quntity = item_quntity         self.item_descrp = item_descrp     def print_itemvaluecost(self):              string = '{} {} @ ${} = ${}'.format(self.nameitem, self.item_quntity, self.item_prc(self.item_quntity * self.item_prc))         valuecost = self.item_quntity * self.item_prc         return string, valuecost     def print_itemdescription(self):         string...

  • Python3 programming help needed LAB*: Program: Online shopping cart (continued) Need the below code edited to run prope...

    Python3 programming help needed LAB*: Program: Online shopping cart (continued) Need the below code edited to run properly for the lab.. class ItemPurchase:     def __init__(self, nameitem='none', item_prc=0, item_quntity=0, item_descrp = 'none'):         self.nameitem = nameitem         self.item_prc = item_prc         self.item_quntity = item_quntity         self.item_descrp = item_descrp     def print_itemvaluecost(self):              string = '{} {} @ ${} = ${}'.format(self.nameitem, self.item_quntity, self.item_prc(self.item_quntity * self.item_prc))         valuecost = self.item_quntity * self.item_prc         return string, valuecost     def print_itemdescription(self):         string = '{}: {}'.format(self.nameitem, self.item_descrp)         print(string , end='\n')         return string class Shopping_Cart:     #Parameter...

  • In this part, you will complete the code to solve a maze.

    - Complete the code to solve a maze- Discuss related data structures topicsProgramming-----------In this part, you will complete the code to solve a maze.Begin with the "solveMaze.py" starter file.This file contains comment instructions that tell you where to add your code.Each maze resides in a text file (with a .txt extension).The following symbols are used in the mazes:BARRIER = '-' # barrierFINISH = 'F' # finish (goal)OPEN = 'O' # open stepSTART = 'S' # start stepVISITED = '#' #...

  • Python 3 Question: All I need is for someone to edit the program with comments that...

    Python 3 Question: All I need is for someone to edit the program with comments that explains what the program is doing (for the entire program) def main(): developerInfo() #i left this part out retail = Retail_Item() test = Cash_Register() test.data(retail.get_item_number(), retail.get_description(), retail.get_unit_in_inventory(), retail.get_price()) answer = 'n' while answer == 'n' or answer == 'N': test.Menu() print() print() Number = int(input("Enter the menu number of the item " "you would like to purchase: ")) if Number == 8: test.show_items() else:...

  • Project Description Allow the user to specify M (the size of the hash table) then, (1)...

    Project Description Allow the user to specify M (the size of the hash table) then, (1) add items found in text file "Project1.txt" to h, an initially-empty instance of a HASH (reject all items that have a key that duplicates the key of a previously added item—item keys must be unique); (2) display h (see format shown below); (3) delete 4 randomly-chosen items from the h; and finally, (4) display h. Note M must be a prime number, so your...

  • I need to write a program based on two finished programs (listm.py and setunion.py) to implement...

    I need to write a program based on two finished programs (listm.py and setunion.py) to implement the intersection operation between two sets of list. The program should not use the Python built-in list and set related functions and operations. I'm sorry about the program format is wrong(no "TAB" space), here is the same question I posted 2 days ago, but the question title is incorrect, there have complete images of my 3 Python program. The link is: https://www.chegg.com/homework-help/questions-and-answers/need-write-program-based-two-finished-programs-listmpy-setunionpy-implement-intersection-o-q44800953?trackid=uNY0ilRc Thank you!...

  • In this lab you will convert lab5.py to use object oriented programming techniques. The createList and...

    In this lab you will convert lab5.py to use object oriented programming techniques. The createList and checkList functions in lab5.py become methods of the MagicList class, and the main function of lab6.py calls methods of the MagicList class to let the user play the guessing game.                              A. (4pts) Use IDLE to create a lab6.py. Change the 2 comment lines at the top of lab6.py file: First line: your full name Second line: a short description of what the program...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT