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

At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get our expert's

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions.

A community for students.

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

MIT 6.00 Intro Computer Science (OCW)
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions

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

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

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 :)
This is very good. Now, write a second piece of code (independently from this one), which simply prints the numbers from 2 to 100.
ok...how's this? http://dpaste.com/493317/
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)
Thanks Polpak for your help. I can't tell you how much I appreciate it. How does this look? http://dpaste.com/499735/
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.
Ok, I would think this would work, but apparently it doesn't. Any ideas? http://dpaste.com/500015/
Haha!!! Figured it out: http://dpaste.com/500041/ The variables have to be declared inside the for loop :)
And lastly my solution to the first problem on problem set #1: http://dpaste.com/500276/ Thanks again Polpak.

Not the answer you are looking for?

Search for more explanations.

Ask your own question