0

Iteration in python

I want to know how I can make a function that receives an integer and changes those digits that are repeated more than 3 times by a 0. Example: delete(199789) >>> 100780

23rd Jul 2020, 10:25 PM
Marco AgĂŒero
Marco AgĂŒero - avatar
1 Answer
+ 3
You can turn the number into a string. Then you use the method count to figure out which digit is in there three times or more. Create a new empty string, then loop over the original, taking either the digit or '0', depending on the result, and adding it to the new string. Finally make an int out of that string. Cram it all in a function. Now please follow thos cooking recipe and create an attempt of your own!
23rd Jul 2020, 10:33 PM
HonFu
HonFu - avatar