Skip to content

Instantly share code, notes, and snippets.

@alevchuk
Last active June 8, 2021 23:44
Show Gist options
  • Save alevchuk/8dc978c9042bf4a3a85780d20d62b0ab to your computer and use it in GitHub Desktop.
Save alevchuk/8dc978c9042bf4a3a85780d20d62b0ab to your computer and use it in GitHub Desktop.
1 + 2 + 3 + ... + n
#!/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