A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

Hi there. Here is my attempt at the first problem in set #1. It's not working the way I want and would very much appreciate some guidance. Thanks in advance :) testmax = int(raw_input("Enter the maximum number to test: ")) while (testmax > 1): if (testmax % 2) == 1: #this gets me all odd numbers under testmax divisor = testmax - 1 #this gets me all integers under testmax as divisors while (divisor > 0): if (testmax % divisor) == 0: #if this is true then testmax is divisible by divisor print testmax, "is divisible by", divi

  • This Question is Closed
  1. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Here it is again: testmax = int(raw_input("Enter the maximum number to test: ")) while (testmax > 1): if (testmax % 2) == 1: #this gets me all odd numbers under testmax divisor = testmax - 1 #this gets me all integers under testmax as divisors while (divisor > 0): if (testmax % divisor) == 0: #if this is true then testmax is divisible by divisor print testmax, "is divisible by", divisor divisor = divisor - 1 testmax = testmax - 1

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

    What did you want it to do? It appears as though it will print out all the factors of all the non-prime numbers less than the number you entered.

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

    Actually I think I may have figured out how to do this differently. I was trying to solve the first problem in problem set #1. A couple of things I didn't realize: 1) there are handouts for each lecture, and 2) I think watching lecture #3 helped a great deal with the first problem set. I was trying to write this without viewing the 3rd lecture. Once I give it another go, I'll post my code again (using dpaste.com this time). Thanks for your help.

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

    Just to summarize, I'm trying to generate a script that will print out the 1000th prime number (starting from 1). So far, I've got one piece of this. I've created a piece of code that will test to see if a number is prime or not. I'm not sure how I go about creating a list of numbers to now cycle through this piece of code. Can someone help? My code is here: http://dpaste.com/491394/ Thanks in advance :)

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

    This is very good. Now, write a second piece of code (independently from this one), which simply prints the numbers from 2 to 100.

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

    ok...how's this? http://dpaste.com/493317/

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

    That'll do. Now take the code you had before and combine it with this one, where you're testing each number as you loop through the numbers from 2 to 100. (testnum in the first code is count in the second)

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

    Thanks Polpak for your help. I can't tell you how much I appreciate it. How does this look? http://dpaste.com/499735/

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

    Wait a sec, I may have misunderstood your last post Polpak. You wanted me to test each number from 2-100 to see if it was prime. The code I just submitted doesn't do that. My code allows the user to choose what number to test, then runs through a for loop to test it. Let me have another go. Sorry for misunderstanding.

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

    Ok, I would think this would work, but apparently it doesn't. Any ideas? http://dpaste.com/500015/

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

    Haha!!! Figured it out: http://dpaste.com/500041/ The variables have to be declared inside the for loop :)

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

    And lastly my solution to the first problem on problem set #1: http://dpaste.com/500276/ Thanks again Polpak.

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