Posts Tagged ‘Problem’

Python: Multiples of Numbers

April 29, 2019 Leave a comment

Python: Multiples of 3 and 5
Problem No.1 in ProjectEuler

This is very easy, very short task to work on, the task as is in ProjectEuler like this “Find the sum of all the multiples of 3 or 5 below 1000.”

My way, as i like to do open code works for any numbers, we will ask the user to enter three numbers, num1 and num2 will be as (3 and 5) in the task, my_range will be as the 1000. So the code can get the sum Multiples of any two numbers in a ranges from 1 to my_range.

Check the answer if you like.

The Code:

# Multiples of 3 and 5
# ProjectEuler: Problem 1

def Multiples_of_N (num1,num2,my_range):


for t in range (1,my_range):

if t %num1==0 or t%num2 ==0 :

tot = tot + t

return tot

print ‘\nDescription: This function will take three variables, two numbers represint the what we want to get there Multiples, then we ask for a range so we will start from 1 to your range.\n’
num1=int(input(‘Enter the first number:’))
num2=int(input(‘Enter the second number:’))
my_range =int(input(‘Enter the range (1, ??):’))

total=Multiples_of_N (num1,num2,my_range)

print ‘\nYou entered ‘,num1,’,’, num2,’ So the sum of all multiples of those number in range (1-‘,my_range,’) = ‘,total

Follow me on Twitter..


Python: Largest product in series

April 28, 2019 Leave a comment

Python: Largest product in a series
Problem 8 @ projectEuler

In Problem 8, ProjectEuler wants to find the thirteen adjacent digits in the 1000-digit number that have the greatest product.

In this task i use a for loop to check each 13-dig set, each time creating a set of 13 digits starting from (0,13) then (1,14)..(2,15)….. and so-on. for each set i get the product of its digits and store it in an a array of [set,total] each time if total of the new set is larger than what we have in the array[total] then we write the new values to the array, we call the array largest.

The Code:

# Largest product in a series
# ProjectEuler: Problem 8

largest =[0,0]

for x in range((1000)):


for each in set1:

tot=tot * int(each)

if tot > largest [1]:

largest[0] = set1

largest[1] = tot


tot =1



print’The thirteen adjacent digits are’,largest[1],’there product is ‘,largest[0]

Follow me on Twitter..

Python: Factorial Digit Sum

April 25, 2019 Leave a comment

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 NdefinitionThe 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 == 1) :

return 1


return num * Factorial_digit_sum(num-1)

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


Follow me on Twitter..

Python: The Factorial

April 22, 2019 Leave a comment

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):



while a <= num:

if num%a==0:

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


a = a + 1

return factors
#Ask the user for a number
num=int(input(“Enter a number: “))

Follow me on Twitter..

My New iPhone 4, a stupid lock phone!!

March 14, 2011 2 comments

I purchased this iPhone 4 from the internet ( 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..

December 14, 2010 4 comments

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 [] 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

November 26, 2010 4 comments

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]