Python Forum
Dictionary based assignment: Need help
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dictionary based assignment: Need help
#1
I've been tasked with creating a program for a hypothetical bike store. We've been given two text documents, one filled with bike parts and the other filled with whole bikes. Both are formatted:
"ID Name Price"
But in the product document, the prices are a collection of all of the part prices and I'm unable to find any help with writing the code that tallys all the prices together and prints the final result.

I also need help writing the user input part of the program, eg the program hs to ask if I'm looking for a part or a product, then the name or the price and respond with the correct information. The link to my github page is listed below the python code that I have so far, any help will be much appreciated.

def load_parts(textfile):   ##Establishes where the parts file is
    parts_file = open(textfile, 'r')
    parts = parts_file.readlines()
    parts_file.close()
    return parts

def load_products(textfile):    ##Establishes where the product file is
    products_file = open(textfile, 'r')
    products = products_file.readlines()
    products_file.close()
    return products

parts_data = load_parts('parts.txt') #Don't know what this does but it works
products_data = load_products('products.txt')

partNames = {} ##Establishes the dictionaries of the part & product names

partPrices = {}

productNames = {}

productParts = {}


for line in parts_data: ##Handles queries regarding parts data & strips the unnecessary information
    splitted_line = line.split(',')
    if len(splitted_line) == 1:
        continue
    ID = splitted_line[0].strip()
    Name = splitted_line[1].strip()
    Price = splitted_line[2].strip()
    
    partNames[ID] = Name
    partPrices[ID] = Price



for line in products_data:          ##Copied from above to handle the product queries & strips unnecessary info.  
    splitted_line = line.split(',') ##This isn't quite finished, need help with this
    if len(splitted_line) == 1:
        continue
    ID = splitted_line[0].strip()
    Name = splitted_line[1].strip()
    Price = splitted_line[2].strip()
    
    productNames[ID] = Name
    productParts[ID] = Price
    
##Below I pulled from an example my teacher gave me but I still need to apply it to this program, need help ##with this

##for x in parts_data:
##     print(x)
##     print('-------------------------------')
##
##run = True
##
##while run:
##    command = input("Please give a command\n")
##    
##    if command[0] == 'a':
##        command = command.split(' ')
##        print("Command recieved: " + command[0])
##        print("Searching for: " + command[1])
##        
##    if command[0] == 'b':
##        print("Execute order 66")
https://github.com/RoyceJ/Dictionary-Assessment---Python-3
Reply


Messages In This Thread
Dictionary based assignment: Need help - by RoyceJ - Aug-21-2018, 02:28 AM
UPDATE: Dictionary based assignment - by RoyceJ - Aug-27-2018, 02:24 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Dictionary based exercise garvind25 2 2,010 Jul-12-2020, 06:53 PM
Last Post: garvind25
  Powerball assignment, how to get correct output of a dictionary ? msp1981 5 3,363 Mar-19-2019, 11:02 PM
Last Post: Yoriz
  logic comparater based on dictionary values ijosefson 3 3,298 Oct-16-2017, 06:04 AM
Last Post: Mekire

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020