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

boogiepicker31 Group Title

Stuck on Exercise 1.8 #3. Question is: Write a program using a for loop that calculates exponentials. Your program should ask the user for a base base and an exponent exp, and calculate base^exp. Just not sure how to format it into a for loop. I created a script: base = input("base: ") expo = input("expo: ") print base**expo This essentially does what the exercise asks but I can't figure out how exactly to put it into a for loop.

  • 2 years ago
  • 2 years ago

  • This Question is Closed
  1. MicroBot Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    if its for python : base=int(raw_input("base: ")) and same process for the other variable.

    • 2 years ago
  2. boogiepicker31 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    The assignment asks us to create a for loop which asks for a base and an exponent, and then calculates base^exp. I don't really understand how that would be formatted into a for loop in python.

    • 2 years ago
  3. MicroBot Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    probably cause you are not supposed ot use the ** operator...you have to recreate the exponential "function". mean if we have 5**3 then you could write it as 5*5*5 .....so think how to implement this with a for loop.

    • 2 years ago
  4. boogiepicker31 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    yeah that makes a lot more sense. i think im getting caught up more on the fact that the basic for loop structure i've been seeing in the MOOC is 'for x in range(a,b,c)' and that's not what I need to use here.

    • 2 years ago
  5. MicroBot Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    ok so the idea is: for loop is an iteration . so knowing that 5**3 can be written as 5*5*5 means you have to iterate 3 times. so if you call that a result you have: result=result*5 (or else written result*=5) and you want to iterate that 3 times: for i in range(0,3): (or for i in range(3):) result*=5 and print the result: print result you just have to substitute the 5 and 3 with the correct variables. hope this helped:)

    • 2 years ago
  6. rsmith6559 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    range( ) can be called three different ways. This is called overloading a function. If range() is called with one argument, it assumes a starting value of 0, and a step value of 1, to a maximum value of the argument. If range() is called with two arguments, the first argument is the start value, the second argument is the max value, and a step value of 1 is assumed. If range() is called with three arguments, the first is the start value, the second is the max value, and the third is the step value. range() actually creates an iterable object (probably a list) and iterates over it. For big loops this can use a noticeable amount of memory, so I use xrange() instead.

    • 2 years ago
  7. algotruneman Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    It might be helpful to look at the Wikipedia "Exponentials" article.

    • 2 years ago
  8. algotruneman Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Exponentials article: http://en.wikipedia.org/wiki/Exponential_function

    • 2 years ago
  9. Invincible Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    run loop exp-1 timess base * base eg base =2 exp =4 2*2 = 4 4*2 = 8 8*2 = 16 run loop exp-1 times...

    • 2 years ago
  10. boogiepicker31 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks for the help all!

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