## Python: Factorial Digit Sum

**Python: Factorial Digit Sum **

** Problem 20 @ projectEuler**

**The Task:** The task in projectEuler P20 is to get the sum of the digits in the number Factorial of 100!

**Factorial Ndefinition**The factorial of a positive integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example, 10! = 10 × 9 × … × 3 × 2 × 1 = 3628800.

**Problem 20** is another easy problem in projectEuler, and we will write two functions to solve it. __First one__ is a Factorial_digit_sum this one will return the factorial of a number. __The second__ function will calculate the sum of all digits in a number N and we will call it sum_of_digits.

**Clarification** As long as i just start solving or posting my answers to projectEuler portal, i am selecting problems and not going through them in sequence, that’s way my posts are jumps between problems, so if i am posting the code to solve problem 144 *(for example)* that does’t meaning that i solve all problems before it.

print of solved screen:

**The Code:**

#Python: Factorial Digit Sum

#Problem No.20 on projectEuler

def Factorial_digit_sum(num):

if (num == 0) :

return 1

else:

return num * Factorial_digit_sum(num-1)

num=100

fact =Factorial_digit_sum(100)

print fact,’is the Factorial of {}.’.format(num)

def sum_of_digits(dig):

t = 0

for each in dig:

t = t + int(each)

print ‘\nThe sum of your number is’,t

sum_of_digits(str(tot1))

## Python: The Factors

**Python: Factors of the Number N**

This is a short task to get the factors of a given number. The Definition of Factors of N is: The pairs of numbers you multiply to get the N number.

For instance, factors of 15 are 3 and 5, because 3×5 = 15. Some numbers have more than one factorization (more than one way of being factored). For instance, 12 can be factored as 1×12, 2×6, or 3×4

In this task we will write a Python code to ask the user for a number N then will get all the pairs number that if we multiply them will get that N number, we will store the pairs in a array ‘factors’.

**The Code:**

def factors_of_n(num):

a=1

factors=[]

while a <= num:

if num%a==0:

if (num/a,a) not in factors:

factors.append((a,int(num/a)))

a = a + 1

return factors

#Ask the user for a number

num=int(input(“Enter a number: “))

print(factors_of_n(num))

## My New iPhone 4, a stupid lock phone!!

I purchased this iPhone 4 from the internet (amazon.com) there was nothing saying that it’s **lock to AT&T** and can’t be used out side USA (__I wonder where is the customer rights to select a carrier__), once i received it i notes that it will not work on Qatar, i am waiting for the unlock solution for OS 4.2.1 BB 3.10.01… No thing till now. For now all i can do is jailbreak it and hope the unlock will be soon released..

## New Battery and Grip..

Last week I had a problem with my New Battery for the Nikon D90 [*Read the post*]. I went to the Nikon Agent – Qatar, they claimed that there where no warranty on the batteries and the chargers; so they can’t change it or re-fund, I decide to get new one and I ask for the price it increased from 41$ to 45$.. Why??

anyway ..

I search the net [*Amazon.com*] and I fond a battery grip + remote + 2x batteries for 64$, it takes 10 days to be delivered [*international transportation-Aramex*] I just received it and here it is.

It’s not bad, nice shape and material, Made In China 🙂 , and the remote was missed!! so no remote..

The batteries are without brand, no name on it I hope it will work fine with me.

[*Click the image to enlarge*]

## Problem with my D90 Battery

**I** have two Batteries(EN-EL3e) for my Nikon D90 (A and B), last time i get the empty signal for one of them (A) and i replace it with the other(B), but i forget to re-charge the empty one(A), i can’t remember for how long time. (15 day’s or more).

Yesterday i run out of charge(B) and then i realize that i did not charge my (A) battery so i pluged it and here is what happen:

When i charged it, the light on the charger started blinking 3 times then stops (no lights). i’d change the charger .. keep the battery in the charge for 6 hours..cleaned the connectors on the battery,,. no thing…

Some websites and posts suggest to Freeze it overnight, so I did 12hours in the freezer.. and no thing.. I think it’s dead.

I think the reason is that I let it to be empty without charges, I will get new one next week and make sure that it will not go to ZERO charge level.

[*New one cost $41 in Nikon Agent – Qatar*]

*Ali,*