Python 45
[Python 100] Python 100
1 100
#!/usr/bin/python
# -*- coding: UTF-8 -*-
tmp = 0
for i in range(1,101):
tmp += i
print ('The sum is %d' % tmp)
The sum is 5050
[Python 100] Python 100
| [ Web Proxy ] |
| Viewing: https://www.runoob.com/python/python-exercise-example45.html | [Back] [Original] |
[Python 100] Python 100
1 100
The sum is 5050
[Python 100] Python 100
| Web Proxy Viewer | New URL | Original Page |
kui
che***[email protected]
1 100
kui
che***[email protected]
252***[email protected]
#!/usr/bin/env python3 # -*- coding: utf-8 -*- a = [x for x in range(1, 101)] b = (a[0] + a[-1]) * (len(a) // 2) if len(a) % 2 != 0: b += a[(len(a) - 1) // 2] print(b)252***[email protected]
xyt***[email protected]
sum()
xyt***[email protected]
ICE
361***[email protected]
ICE
361***[email protected]
jc
228***[email protected]
jc
228***[email protected]
yulinshui
132***[email protected]
while
i=0 total=0 while i<=100: total=total + i i = i +1 print(total)yulinshui
132***[email protected]
123
117***[email protected]
# coding: utf-8 def my_sum(x): if x == 100: return 100 else: return x + my_sum(x + 1) print(my_sum(1))123
117***[email protected]