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?
may not make a different but I would put if x % i == 0: (put in a space before and after %
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)
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.
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.
Thank you!!! I didn't have the print statement...so simple.
No problem :D
Join our real-time social learning platform and learn together with your friends!