Please see attachment. Any help is appreciated! :D

Dani AI

Generated

The advice from and is on point: start by turning the PDF into an explicit, tiny specification before any coding. The most useful next step is a short checklist and a minimal design that fits most introductory Python file-processing tasks.

  • Clarify the input: line format, delimiter (space, comma, CSV), presence of a header, sentinel values, blank lines, or comment lines.
  • Clarify the output: exact formatting, rounding, ordering, and any example outputs in the PDF.
  • Clarify constraints: expected file size (stream vs. store), data types (int/float/string), and performance/complexity limits.
  • Produce 3–6 plain-English steps (pseudocode) that map input -> processing -> output.

A small, robust structure reduces errors: separate parsing, updating state, and finalizing output. For many problems a streaming approach is best (avoid storing every line when only aggregates are needed). Wrap conversions in try/except to report bad input lines (use enumerate to include line numbers in diagnostics).

Example skeleton (keeps responsibilities separated and works for EOF or sentinel-style inputs):

import sys

def parse_line(line):
    s = line.strip()
    if not s:
        return None
    parts = s.split()        # adjust for CSV if needed
    try:
        return [int(p) for p in parts]
    except ValueError:
        return [float(p) for p in parts]

def process(items):
    # compute required result(s) from list-of-items or running state
    return None

def main(path):
    data = []
    with open(path, 'r', encoding='utf-8') as fh:
        for ln in fh:
            item = parse_line(ln)
            if item is not None:
                data.append(item)
    print(process(data))

if __name__ == '__main__':
    main(sys.argv[1])

Debugging notes: verify the working directory and file path, test with a 5–10 line sample that matches the PDF, check encoding issues, and add prints or assertions to check intermediate state. If memory is a concern, convert data.append into on-the-fly aggregations (sum/count/max) instead of storing all rows.

Recommended Answers

All 2 Replies

Presumably you've been taught everything you need to know in class to handle this assignment so you already have the tools you need.
Step 1 is to make sure you understand the problem. Do this by working your way through the steps your program would need to do in english.
I.e. read a file, know when it's finished reading the file, need to store the values so how do I do that, etc.

Once you've got your flow sorted you can start with the actual code, building it up a step at a time. And once you've got something to show us and are still having trouble then people might be more interested in helping. Make an effort and then ask for help.

Personally, this isn't a hard problem and either you are too lazy to try or didn't understand the course material so far. Both problems are fixable with a little work on your part.

The PDF is the assignment but nothing more. Time to design your program, step by step, then write it according to those steps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.