Oktatás * Programozás 2 * Szkriptnyelvek * levelezősök Félévek Linkek * kalendárium |
EnPy3 /
20121001bsum of natural numbers from 1 to 100 There is a well-known story about Karl Friedrich Gauss. Once in the primary school the math teacher gave the exercise to calculate the sum of natural numbers from 1 to 100 (included). The teacher thought that the children will occupy themselves with the exercise but Gauss solved it in 30 seconds. (More info here.) Exercise Solve this problem using the Python shell (use just the shell). Variation Take the natural numbers from 1 to 100 (included), and calculate the sum of the digits in the numbers. For instance, the sum of the digits in the numbers Help: The >>> list('python') ['p', 'y', 't', 'h', 'o', 'n'] |
Blogjaim, hobbi projektjeim * The Ubuntu Incident [ edit ] |