-1

The program should print the entries which are divided into three without the remainder. The problem is "TypeError : not all arguments converted during string formatting python " in the bottom

numbers = [ ]
while True:
    inputNumber = (input("Enter a number if you want to terminate this, please tap on 'q' : "))
    if inputNumber == "q":
        break    
    numbers.append(inputNumber)
    


sum = 0
for i in numbers:
    sum+=int(i)

print("Sum of the inputs : ", sum)

#unexecutable lines  
for i in numbers:
    if(i%3 == 0):
        print(i)
1
  • 4
    Where you have i%3, i is a string, not a number. Commented Apr 2, 2022 at 7:52

1 Answer 1

0

Variable i is in string format.

Hence type cast it to int before carrying out calculation:

#unexecutable lines  
for i in numbers:
    if(int(i)%3 == 0):
        print(i)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.