Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

Atiaboussa Group Title

Hello everyone Since last week I'm very upset with the problem set 1. the first program istead of doing the same thing from 1 month to 12 months How can I use loop to do it one time. What I want is an alogarithm for the first program. Thank you

  • 3 months ago
  • 3 months ago

  • This Question is Open
  1. lopus Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    hi you can see here: http://openstudy.com/study#/updates/53504232e4b0b39169cd4cdd

    • 3 months ago
  2. lopus Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    but mean: p1*p2*p3*pn <= e**N == log(p1)+log(p2)+log(pn)< N result=result + math.log(primeNumber) ratio= result/N

    • 3 months ago
  3. odweaverel Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    I'm assuming, based on your question, that you are already good with computing the formulas and you just want to know how to write the code so you don't have to copy and paste it 11 times to make twelve copies of the calculation. the best way to get the information is to watch the lectures and recitation, I believe (section 4 of unit 1 ) is where loops are covered. However, if that's too much sifting through to do I'll give you a shortened explanation. There are two different loops. One is the While loop and the other is the For loop. The while loops is relatively self-explanatory; the block of code in the while loop will run WHILE a certain variable meets the condition (true, false, x=3...). A For loop runs a block of code a specific number of times. the syntax for a while loop in python is (hash-tags are comments): #declare a variable of any name. i is regularly used #and the variable is not limited to numbers somevariable = 0 #this while loop will run twelve times total while (somevariable <12): #indent instead of bracketing #the next line of code is there to give the loop some way to end. somevariable = somevariable + 1 #insert block of code (i.e. calculations and print) #remove indent to end while loop the syntax for a For loop is: #this loop will run twelve times total #the 0 is the starting place #the 12 is the limit #and the 1 is the amount added to the number each time it's repeated for i in range of (0,12,1): #indent #insert block of code (i.e. calculations and print) #remove indent to end while loop You should play around with these concepts to find a way that works for you in learning them. Finally here is some reading material that was given in section 3 that will help your understanding of loops. although I believe this refers to some syntax that can be used in a different version of python because the whole end=" " thing doesn't work in 2.5 (the classes version) http://beastie.cs.ua.edu/cs150/book/index_14.html I hope that answers your question.

    • 2 months ago
    • Attachments:

See more questions >>>

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.