Darlene Porter
Darlene Porter

Reputation: 3

Python, loop program

Can someone tell me what i am doing wrong? I am writing a program using loops in Python 3.x, but when i execute program i am getting a traceback error:

multiple of 13 is 195 and factors are as follows Traceback (most recent call last): File "C:/Users/Darlene/Desktop/Chapter 4/program4_2.py", line 19, in list1.append(j) AttributeError: 'dict' object has no attribute 'append'

this is the code i entered:

def main():
    for i in reversed(list(range(100,201))):
    if i%13==0:
        print("multiple of 13 is",i,"and factors are as follows")
        list1 = {}
        for j in list(range(2,i+1)):
            if i%j == 00:
            list1.append(j)
        print(list1)
main()

Upvotes: 0

Views: 58

Answers (2)

Xiflado
Xiflado

Reputation: 176

As commented by Luke Park, list1 = {} will declare a dictionary. What you need is list1 = [].

Also, range will already return a range type that can be handled by most methods and loops so there's no need to cast it to a list.

Upvotes: 1

tanaydin
tanaydin

Reputation: 5306

list1 must be an list like so...

list1 = []

you defined it as an dict, and as python said

'dict' object has no attribute 'append'

Upvotes: 0

Related Questions