May-05-2017, 06:48 PM
I am incredibly new to python (I'm officially on my fourth day of learning) and as a test of what I've learned so far, I wanted to make a simple Explicit Formula calculator. The formula is:
a(n) = a(1) + (n - 1)d
This is what I came up with:
a(n) = a(1) + (n - 1)d
This is what I came up with:
aone = raw_input("Enter the first term: ") n = raw_input("Enter the n term: ") d = raw_input("Enter the difference: ") answer = n - 1 answer = answer * d answer = answer + aone print answerThe printout from the terminal is this:
Output:python expForm.py
Enter the first term: 2
Enter the n term: 100
Enter the difference: 5
Traceback (most recent call last):
File "expForm.py", line 5, in <module>
answer = eval('aone + (nterm - 1) * diff')
File "<string>", line 1, in <module>
TypeError: unsupported operand type(s) for -: 'str' and 'int'
I'm sorry if I look like the biggest imbecile on the planet, but this is beyond me at this stage in my coding abilities. Sorry. :(