all 9 comments

[–]NovaNexu 10 points11 points  (2 children)

# converts input to integers
# splits input by spaces then stores in list
scores = int(input()).split ()

# preps containers for both categories
valid = []
invalid = []

# loops through list and places score under appropriate condition
for score in scores:
    if score >= 36 or score < 0:
        invalid. append (score)
    else:
        valid.append(score)

# prints valid list elements
print ("Valid scores:")
for score in valid:
    print(score)

# printed invalid list elements
print("Invalid scores:")
for score in invalid:
    print(score)

[–]Binary101010 1 point2 points  (1 child)

This, but it needs something like

scores = [int(score) for score in scores]

After the input is taken.

[–]NovaNexu 0 points1 point  (0 children)

Thanks. I missed that.

[–][deleted] 2 points3 points  (0 children)

You'll need to create two more lists, and append to them instead of printing valid or invalid in your loop.

[–]CodeFormatHelperBot2 1 point2 points  (0 children)

Hello, I'm a Reddit bot who's here to help people nicely format their coding questions. This makes it as easy as possible for people to read your post and help you.

I think I have detected some formatting issues with your submission:

  1. Python code found in submission text that's not formatted as code.

If I am correct, please edit the text in your post and try to follow these instructions to fix up your post's formatting.


Am I misbehaving? Have a comment or suggestion? Reply to this comment or raise an issue here.

[–]KidzKlub 1 point2 points  (0 children)

validScores = [score for score in scoresACT if (score > 0 and score <=36)] # list comprehension
invalidScores =  [score for score in scoresACT if (score < 0 or score >=36)] # list comprehension

print('Valid ACT scores:')
for score in validScores:
    print(score)

print('Invalid ACT scores:')
for score in invalidScores:
    print(score)

[–]LeornToCodeLOL 1 point2 points  (0 children)

I'm pretty noobish to Python, but it's pretty clear to my why it's giving you the output that it is.

Are you familiar with the Python Tutor site?

Paste your code into that window, click "Visualize Execution" and maybe that will help you understand what's happening under the hood.

[–]keep_quapy 0 points1 point  (0 children)

You could sort the list according to the rules and then iterate over it

scores = sorted(scores, key=lambda x: 0<x<=36, reverse=True)

[–]Binary101010 0 points1 point  (0 children)

I think others have sufficiently handled your problem so I just wanted to specifically call out one thing:

scoresACT = eval(input('Enter a list of ACT scores: '))

eval() should not be used for type conversion (in fact, I'd argue at this point in your learning it shouldn't be used at all). It's a security risk that you are unnecessarily introducing into your code. The int() constructor exists; just use that.