Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

minimallinux

  • 2 years ago

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 ?

  • This Question is Closed
  1. msmithhnova
    • 2 years ago
    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.

  2. eparizi
    • 2 years ago
    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

  3. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Ask a Question
Find 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
  • 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.