python - TypeError raised while trying to use range -


while i'm running following code shows typeerror:

a = int(input("enter iteration value:"))  b=[]  c in range[0,a]:     d=int(input("enter:"))     b.append(d)  f=0     e in b:     f = f + e  print f 

it shows following error

enter iteration value:5 traceback (most recent call last):   file "/var/app/eclipse/plugins/org.python.pydev_3.5.0.201405201709/pysrc/pydevd.py", line 1845, in <module>     debugger.run(setup['file'], none, none)   file "/var/app/eclipse/plugins/org.python.pydev_3.5.0.201405201709/pysrc/pydevd.py", line 1373, in run     pydev_imports.execfile(file, globals, locals)  # execute script   file "/opt/odoo/v7.0_cust_mod/python/print.py", line 68, in <module>     c in range[0,a]: typeerror: 'builtin_function_or_method' object has no attribute '__getitem__' 

you using wrong syntax range() function:

for c in range[0,a]: 

note square brackets, should use parentheses instead:

for c in range(0, a): 

the square brackets used subscriptions, means python try , use __getitem__ method on range function object. there no such method, why traceback.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -