Last active
June 8, 2021 23:44
-
-
Save alevchuk/8dc978c9042bf4a3a85780d20d62b0ab to your computer and use it in GitHub Desktop.
1 + 2 + 3 + ... + n
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python | |
n = int(input("Enter a integer: ")) | |
total = 0 # к этой будем прибавлять | |
print(n) | |
for i in range(1, n + 1): # прибавлять будем i, которая сначала 1, | |
# потом 2, и так до n. у функции range() | |
# второй аргумент всегда на один | |
# больше, поэтому даем n + 1 | |
print(i) | |
total += i # прибавляем | |
print(total) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment