Ask your own question, for FREE!
Computer Science 6 Online
OpenStudy (kandi):

I am trying to run the following python script: x = 100 divisors = () for i in range(1,x): if x%i == 0: divisors = divisors+(i,) When run, I do not get an answer. Suggestions?

OpenStudy (anonymous):

may not make a different but I would put if x % i == 0: (put in a space before and after %

OpenStudy (anonymous):

What output are you looking for? Is that all the code? I'm thinking that you should append to your list instead of just adding it. Tr this divisors.append(i)

OpenStudy (anonymous):

Also, if that is your complete code, you have forgotten to write your print statement. I.e. print divisors I ran your code and it works fine for me.

OpenStudy (anonymous):

One more thing, forget the "divisors.append(i)" code i gave you earlier, that code only works for lists and I see you initialised "divisors" as a tuple. Though you can use the code I mentioned if you change your 2nd line to divisors = [] Hope that sorts you out.

OpenStudy (kandi):

Thank you!!! I didn't have the print statement...so simple.

OpenStudy (anonymous):

No problem :D

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!