Problem 1

来源:互联网 发布:python 定义矩阵 编辑:程序博客网 时间:2024/04/28 00:29
# -*- coding = gbk -*-#!/usr/bin/python'''Problem1: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.'''def findnumbers (number):    i = 1    n = 0    sum = 0    while (i<number):        if i%3 == 0 or i%5 == 0:            sum = sum + i            n = n + 1        i = i + 1    print unicode(" %d %d" %(sum, n))        findnumbers(10)findnumbers(100)findnumbers(1000)


0 0