And the python .... 03/08/2010
Hello, this section is meant for sharing things that don't fall under the category of "linux/*nix experiences". So my first one. Some code from python...( i have been doing python for about 3 weeks now :P ).Here goes: OBTAINING A DIGIT FROM A NUMBERSometimes one would need to obtain a digit from a number with more than one digit, well, here's how i did it in python: This method takes a number "intNum" and passes it to a while loop the last digit is extracted from intNum then added to the variable "total", later the "intNum" is divided by 10 to obtain the remaining first digits. This is done until 0 remains (which is when the number is a single digit and in this case it's added to the "total" variable). So basically what it does is take for example a number 22, then splits it to 2 then 2 then add it like so 2 + 2 = 4. def zap(intNum): total = 0 while intNum != 0: last = intNum % 10 total += last intNum = intNum / 10 return total If there's any questions or ideas, feel free to comment. ## Comments## Leave a Reply | ## Archives## Categories |