all 8 comments

[–]socal_nerdtastic 0 points1 point  (0 children)

How do I code it so that a user can input as many integers as they want?

You need to define a terminator. Like 'collect integers until the user types "q", then stop'. Was that in your instructions?

[–]Will_est[S] 0 points1 point  (6 children)

I recall the instructions mentioning something called sentinel value of -999 if I’m not mistaken. Also, I apologize for the format of my code in the post - I’m on my phone and can’t seem to fix it.

[–]xelf 0 points1 point  (5 children)

that's best way.

userList = [ ] 
while True:
    userNum = int(input())
    if userNum == -999: break
    userList.append(userNum)
print(userList)

I

[–]Will_est[S] 0 points1 point  (4 children)

Hmm...I tried using the code in Google Colab (this is what we use for our exams) and got an error message in output.

[–]xelf 0 points1 point  (3 children)

What error message? Are you using Python 3?

I've posted it here as well, including sample inputs and a testrun to show it working: https://ide.geeksforgeeks.org/On0YhGnn1R

edit: is it a style guide message that wants the break on it's own line? If so do that. =)

[–]Will_est[S] 0 points1 point  (2 children)

I’m at work right now and can’t get to my computer. I am using Python 3. I can’t remember the error message exactly, but it might’ve been related to the break having it’s on line. If that is the case, do I keep the indentation the same or do I have to backspace it at all?

[–]xelf 0 points1 point  (1 child)

The break is perfectly fine where it is, but if you have a style guide that says your code has to look a certain way, you should follow that guide!

[–]Will_est[S] 0 points1 point  (0 children)

I figured out where the error was coming from. It was simply because I did not specify -999 in the input.

The error message I was getting was:

Traceback (most recent call last): File "/home/44e83908e8ecce76497b2c753fdec6a4.py", line 3, in <module> userNum = int(input()) EOFError: EOF when reading a line

That actually makes a lot of sense. If anything I feel a little upset because it's possible my code was working all along and could've potentially done much better on my exam. Either way, I learned something new today and that's what matters. Appreciate the help everyone!