1

I want to specify my list type by pressing -1 then I want to add numbers to the numbers list then I want to add those numbers up when I press "F"

For some reason it doesn't listen to me and adds F to the list which gives me an error

thank you in advance.

numbers =[]
ListType = int(input())
if ListType < 0:
    while True :
        if input()!= "F":
            value = input()
            numbers.append(value)
        else:
            print(sum(numbers))
1
  • Could you fix your indentations around the first if statement. I'm guessing you would move it backwards, but please clarify it Commented Oct 1, 2019 at 20:22

1 Answer 1

1

2 issues here:

  1. You are calling input() in while loop due to which the loop will only check the condition with the odd inputs and won't append that in the list, thus, half of the inputs will be ignored.

  2. sum() require a numeric list. But since values taken from input() aren't type-casted, therefore, are appended as string. You can confirm this by using print(type(numbers[0])) somewhere in the code.

Therefore, after correcting these issues, your code would look like:

numbers =[]
ListType = int(input())
if ListType < 0:
    while True:
        value = input()
        if value != "F":
            numbers.append(int(value))
        else:
            print(sum(numbers))
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you! This works in Pycharm but when i try to make it go through my uni's exercice verifier i get this error : EOFError: EOF when reading a line. Any ideas?
@MaxBouzari What is the input format in that verifier?
I'm not entirely sure what you mean? i just copy and past from pycharm to the website in a little box and it verifies is automatically

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.