Got Homework?
Connect with other students for help. It's a free community.
Here's the question you clicked on:
 0 viewing
minimallinux
Group Title
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 ?
 2 years ago
 2 years ago
minimallinux Group Title
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 ?
 2 years ago
 2 years ago

This Question is Closed

msmithhnova Group TitleBest ResponseYou've already chosen the best response.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 years ago

eparizi Group TitleBest ResponseYou've already chosen the best response.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
 2 years ago
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
 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.