Created
March 26, 2015 00:55
-
-
Save sicknarlo/1e99c6dd85e1fecbb615 to your computer and use it in GitHub Desktop.
Prints the recurrence relation to the nth term
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
# 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