Python Forum
Newb: Simple Explicit Formula
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Newb: Simple Explicit Formula
#1
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:

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 answer
The 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. :(
Reply


Messages In This Thread
Newb: Simple Explicit Formula - by Duplicitous - May-05-2017, 06:48 PM
RE: Newb: Simple Explicit Formula - by buran - May-05-2017, 07:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python newb need help Fictile 1 260 Apr-02-2024, 03:28 AM
Last Post: buran
  NameError issue with daughter's newb code MrGonk 2 1,479 Sep-16-2021, 01:29 PM
Last Post: BashBedlam
  Python “Formula” Package: How do I parse Excel formula with a range of cells? JaneTan 1 2,722 Jul-12-2021, 11:09 AM
Last Post: jefsummers
  Being explicit about the items inside a tuple argument rudihammad 3 2,487 Dec-04-2019, 08:10 AM
Last Post: perfringo
  Simple newb string question Involute 2 2,270 Sep-08-2019, 12:50 AM
Last Post: Involute
  please help this newb install pygame iofhua 7 6,017 May-15-2019, 01:09 PM
Last Post: buran
  Newb question: Debugging + Linting Python in Visual Studio Code Drone4four 1 2,456 Apr-15-2019, 06:19 AM
Last Post: perfringo
  Newb question about %02d %04d bennylava 30 19,866 Mar-05-2019, 11:23 PM
Last Post: snippsat
  Pthyon 3 question (newb) bennylava 11 6,030 Feb-28-2019, 06:04 PM
Last Post: buran
  newb selfie PatM 5 3,663 Feb-19-2019, 12:20 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020