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

minimallinux

How does iterMul work anyone ? def iterMul(a, b): result = 0 while b > 0: result += a b -= 1 return result It returns the product but how ?

  • one year ago
  • one year ago

  • This Question is Closed
  1. msmithhnova
    Best Response
    You've already chosen the best response.
    Medals 0

    The loop is based on b and there loops b many times. Inside the loop it simply adds a so say you have a of 3 and b of 4. If you add 3 for times you get 3+3+3+3 which is the same as 3*4.

    • one year ago
  2. eparizi
    Best Response
    You've already chosen the best response.
    Medals 1

    as long as b is greater than 0 (while b > 0) it's adding the value of "a" to the local variable "result" (result += a) and also subtracting "b" by 1 (b -= 1), so be goes towards 0, and for each iteration another "a" is added to "result"! , we'll have "b" iterations (for each positive "b") and it makes b*a

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