Skip to content

Instantly share code, notes, and snippets.

@sicknarlo
Created March 26, 2015 00:55
Show Gist options
  • Save sicknarlo/1e99c6dd85e1fecbb615 to your computer and use it in GitHub Desktop.
Save sicknarlo/1e99c6dd85e1fecbb615 to your computer and use it in GitHub Desktop.
Prints the recurrence relation to the nth term
# Prints out recurrence relation based on 3 inputs: operations, relation, and term
# get input of operations
operations = input()
#split operations by space into list
op_list = operations.split(' ')
# get initial number
init = input()
init = int(init)
# get n
n = input()
n = int(n)
print "Term 0: " + str(init)
for x in range(1, n + 1):
for i in op_list:
if i[0] == '+':
init += int(i[1:])
elif i[0] == '-':
init -= int(i[1:])
elif i[0] == '*':
init *= int(i[1:])
elif i[0] == int(i[1:]):
init /= int(i[1:])
print "Term " + str(x) + ": " + str(init)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment