Accademia:Projecteuler 1.py
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000.
#!usr/lib/env python3 def multiple(multiple,value): multiples = [] for number in range(multiple, value, multiple): multiples.append(number) return multiples def sum_of_numbers(the_range): sum_of_numbers = 0 for number in range(the_range): if not number % 3 or not number % 5: sum_of_numbers += number return sum_of_numbers if __name__ == '__main__': somma = 0 for i in range(10): # inutile controllare 0,1,2 sappiamo già che non vanno bene così si risparmiano preziosi nanosecondi. if i % 3 == 0 or i % 5 == 0: somma += i print(somma) the_range = int(input('range: ')) print(sum_of_numbers(the_range)) multiplo = int(input('multiple: ')) valore = int(input('value: ')) print(multiple(multiplo,valore))