A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 5 years ago
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?
anonymous
 5 years ago
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?

This Question is Closed

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0may not make a different but I would put if x % i == 0: (put in a space before and after %

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0What 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)

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Also, 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.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0One 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.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Thank you!!! I didn't have the print statement...so simple.
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.