A community for students.
Here's the question you clicked on:
 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
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

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

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0What did you want it to do? It appears as though it will print out all the factors of all the nonprime numbers less than the number you entered.

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

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

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0This is very good. Now, write a second piece of code (independently from this one), which simply prints the numbers from 2 to 100.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0ok...how's this? http://dpaste.com/493317/

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

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Thanks Polpak for your help. I can't tell you how much I appreciate it. How does this look? http://dpaste.com/499735/

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Wait a sec, I may have misunderstood your last post Polpak. You wanted me to test each number from 2100 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.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Ok, I would think this would work, but apparently it doesn't. Any ideas? http://dpaste.com/500015/

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Haha!!! Figured it out: http://dpaste.com/500041/ The variables have to be declared inside the for loop :)

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0And lastly my solution to the first problem on problem set #1: http://dpaste.com/500276/ Thanks again Polpak.
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.