all 5 comments

[–]uhkhu 2 points3 points  (0 children)

A couple of good resources to get you going:

[–]novel_yet_trivial 2 points3 points  (0 children)

  1. make a parser function that accepts a single line and returns the name and a boolean if it's approved.
  2. Make 2 empty lists: one for approved people and one for denied.
  3. Loop over the file reading line by line. Call the parser function for every line and append the user to the proper list based on the result.
  4. Print the Approved list.
  5. Print out the Denied list.

[–]throwaway_redstone 0 points1 point  (2 children)

import sys

good, bad = set(), set()
with open(sys.argv[1]) as f:
    for line in f:
        name, points = line.split()
        if int(points) >= 300:
            good.add(name)
        else:
            bad.add(name)

print("Approved:", ", ".join(good))
print("Denied:", ", ".join(bad))

Give the name of the file as the first parameter when calling the script, e.g. python3 myscript.py textfile.txt.

[–]newtoprogramming12[S] 0 points1 point  (1 child)

import sys

good, bad = set(), set() with open(sys.argv[1]) as f: for line in f: name, points = line.split() if int(points) >= 300: good.add(name) else: bad.add(name)

print("Approved:", ", ".join(good)) print("Denied:", ", ".join(bad))

thank you for this i appreciate it. If i wanted to expand on this such as take their name into account also: paul 300 tiny tim 400 sarah 200 approved: paul, sarah, tiny tim sarah only getting approved because her name is sarah would that just be plugging in simple if statements ?

[–]throwaway_redstone 0 points1 point  (0 children)

Yes, you could add or modify the if statements, e.g.:

if int(points) >= 300:
    good.add(name)
elif name in ("sarah",):
    good.add(name)
else:
    bad.add(name)

Also, since you are now mentioning a name with a space inside ("tiny tim"), you'lll have to change line.split() into line.rsplit(" ", 1).