Skip to content

Instantly share code, notes, and snippets.

@eugeneai
Created February 17, 2023 05:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eugeneai/6777016fefc1a6a6d165948a7887c4ac to your computer and use it in GitHub Desktop.
Save eugeneai/6777016fefc1a6a6d165948a7887c4ac to your computer and use it in GitHub Desktop.
# Arithmetic progression
# Input
# Second task : calculate sum of ai
debug = True
allow_input = False if debug else True
if allow_input:
n=int(input("Input n: "))
a1=int(input("Input a1: "))
d=int(input("Input d: "))
else:
n = 20
a1 = 1
d=10
i=1
a=a1
while i<n:
a=a+d
i=i+1
if debug:
# Check our algorithm
b = a1+(n-1)*d
assert b == a
# Output
print('Memeber number', n, 'of the progression is', a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment