0

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()
tanaydin
5,32632 silver badges50 bronze badges
asked Apr 10, 2016 at 0:55
1
  • If I remember correctly, list1 = {} declares a dictionary, not a list, thus there is no append method associated with it. Commented Apr 10, 2016 at 1:01

2 Answers 2

1

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.

answered Apr 10, 2016 at 1:11
Sign up to request clarification or add additional context in comments.

Comments

0

list1 must be an list like so...

list1 = []

you defined it as an dict, and as python said

'dict' object has no attribute 'append'

answered Apr 10, 2016 at 1:10

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.