A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

Kandi

  • 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
  1. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  2. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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)

  3. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  4. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  5. Kandi
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  6. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    No problem :D

  7. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

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
  • 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.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.