Python Forum
I'm blocked in the construction of my program [Novice]
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I'm blocked in the construction of my program [Novice]
#1
Hello, here's my program:

oooooo =['fg', 'dh', 'df', 'hg', 'sd', 'hnb', 'eee', 'rh', 'ddd', 'vvvv']
aaaaaaa = [542, 861,532,7854,2213,45612,7865,1535,453,452]
bbbbbb = [8888,7777,4444,1111,2222,333,555,444,123,453]
ccccc = [8888,666,555,4444,222,555,666,444,111,222]
fffff = [444,555,555,555,666,8888,4444,8888,4444,77777]
abcd = [oooooo]+[aaaaaaa] +[bbbbbb]+[ccccc]+ [fffff]




def ppp(x, y):
    return ((y - x)/x)* 100

def iii(*e):
        xx = []
        yy= []
        zz = []
        for i in range(len(e[0])):
            xx += [ppp(e[1][i], e[2][i])]
        for j in range(len(e[0])):
            yy += [ppp(e[2][j], e[3][j])]
        for l in range(len(e[0])):
            zz += [ppp(e[3][l], e[4][l])]
        return xx, yy, zz
And here what I get with >>> iii(abcd):
Error:
Traceback (most recent call last): File "<pyshell#125>", line 1, in <module> iii(a) File "C:/Python34/poiuy.py", line 19, in iii xx += [ppp(e[1][i], e[2][i])] IndexError: tuple index out of range
I don't understand why my list is called a tuple because there are no () but [] and I don't understand why the index is out of range while it shouldn't because 0 =< i < 10, and the length of the lists = 10.

I would like someone to help me please, thank you!
Reply
#2
First of all - get rid of habit to use cryptic variable names as soon as possible... Your variable names are plain nightmare....
As to your question - look at line 14: def iii(*e):
By using star in front of e, you make e a catch-all argumenmt, i.e. it turns to be a tuple that holds what you pass as arguments. In your case you pass a single list of lists, so it becomes a single element tuple. That is why e[1] on line 19 raise that exception. Add
print(type(e))
print(e)
to see for yourself.
Finally, read https://python-forum.io/Thread-Basic-Nev...n-sequence
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Why my graph is blocked at 4.2 bars whithout use the valve on my modelisation ? tudy62 1 192 Apr-15-2025, 11:24 AM
Last Post: Axel_Erfurt
  sharepoint: Access has been blocked by Conditional Access policies CAD79 0 2,157 Jul-12-2024, 09:36 AM
Last Post: CAD79
  [Solved] Novice question to OOP: can a method of class A access attributes of class B BigMan 1 1,903 Mar-14-2022, 11:21 PM
Last Post: deanhystad
  Total electric construction cost project SecondSandwich94 2 3,095 Jul-21-2021, 09:37 PM
Last Post: deanhystad
  Python Complete novice: Want to run a vulnerability script bhanney23 1 3,906 Sep-18-2020, 09:27 AM
Last Post: Aspire2Inspire
  (Complete Novice) Code not working PythonGainz 9 5,679 Mar-21-2020, 05:53 PM
Last Post: buran
  Novice use of a CSV preliator 1 2,595 Dec-26-2019, 08:05 PM
Last Post: Axel_Erfurt
  Blocked chromebook arsenal58 1 2,672 Feb-05-2019, 02:36 PM
Last Post: perfringo
  Trivial novice question: information gathering tools in Python Drone4four 1 2,892 Nov-10-2018, 01:41 AM
Last Post: Larz60+
  Class construction in python Alberto 3 5,172 Jul-18-2017, 03:37 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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