Recent Changes - Search:

Oktatás

* Programozás 1
  + feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

Teaching

* Programming 1 (BI)
  ◇ exercises
  ◇ quick link

* Scripting Languages
  ◇ exercises
  ◇ quick link

teaching assets


Félévek

* aktuális (2023/24/2)
* 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