Python Programing Challenge - Let's Multply with a loop

Using "while" to do stuff multiple times - Python3

Define a procedure loopWithWhile(m, n), which returns the product of m and n, assuming that n is a positive integer. Don't use the math function "*" but instead, use a while loop, and the math function "+".
Your function should have type (num, positiveInt) -> num

def loopWithWhile(a,b):
# <put your "while" code here and replace the following line>
   return a*b

def main():
   m =2
   n = 21
   x = loopWithWhile(m,n)
   print("m * n = ", x)


main()



Now re-implement with a "forLoop"

No comments:

Post a Comment