Recent Changes - Search:

Oktatás

* Programozás 2
  + feladatsor
  + C feladatsor
  + Python feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

* levelezősök
  + Adator. prog.
  + feladatsor
  + quick link

teaching assets


Félévek

* 2024/25/1
* archívum


Linkek

* kalendárium
   - munkaszüneti napok '20
* tételsorok
* jegyzetek
* szakdolgozat / PhD
* ösztöndíjak
* certificates
* C lang.
* C++
* C#
* Clojure
* D lang.
* Java
* Nim
* Scala


[ edit | logout ]
[ sandbox | passwd ]

20121001b

sum 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 [10, 11, 12] is 6 (1+0+1+1+1+2=6).

Help:

The list() built-in function can get a string too as a parameter. The returned value will be a list, which contains the characters of the string. Example:

>>> list('python')
['p', 'y', 't', 'h', 'o', 'n']
Cloud City

  

Blogjaim, hobbi projektjeim

* The Ubuntu Incident
* Python Adventures
* @GitHub
* heroku
* extra
* haladó Python
* YouTube listák


Debrecen | la France


[ edit ]

Edit - History - Print *** Report - Recent Changes - Search
Page last modified on 2017 August 04, 09:40