Python-Übungsbeispiel 45

Python 100例Python 100 Beispiele

Problem:Berechne die Summe der Zahlen von 1 bis 100.

Programmanalyse:Keine

Programmquellcode:

Beispiel

#!/usr/bin/python # -*- coding: UTF-8 -*- tmp = 0 for i in range(1,101): tmp += i print ('Die Summe ist %d' % tmp)

Die Ausgabe des obigen Beispiels ist:

The sum is 5050

Python 100例Python 100 Beispiele

Andere Erweiterungen