Python basic function

Python basic function
0

#1

write an iterative function that takes two parameters and uses repeated subtraction to return the value of a%b


#2

What have you tried, what are you stuck on, what do you not understand?


#3

You mean recursive function…?


#4

I dont understand how to do it


#5

yes i guess a recursive


#6

to subtract what inside the recursive function? Its little confusing


#7

Right but I don’t know what you know. I don’t know if you know any basic python, I don’t know if you know any basic maths, if you understand what they’re asking you

  • do you understand what modulo is, eg what the answer to 4 mod 2 or to 6 mod 4 is? (Python uses the % symbol for modulo - eg 4 % 2)
  • do you understand how it is related to repeated subtraction?
  • do you understand how to declare, assign and update a variable?
  • do you understand how to write a loop?

#8

I know all of that , i just don’t understand how to relate it to subtraction
I know basic python !


#9

So

10 mod 3

Is 1.

I can get that valie by subtracting 3 from 10, then 3 from the remainder of that and so on over and over until a specific condition is met.


#10

It is a recursive function.