Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Python: object related syntax errors

 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to generate 20 5 digit integer random numbers:
I have written followingcode:




I am getting following errors:

Traceback (most recent call last):
 File "/home/zulfi/PycharmProjects/sort/20_5digitRandom.py", line 17, in <module>
   objTestRandom.main()
 File "/home/zulfi/PycharmProjects/sort/20_5digitRandom.py", line 13, in main
   self.genrate1000_5difit_RandomNum()
AttributeError: 'TestRandom' object has no attribute 'genrate1000_5difit_RandomNum'

Process finished with exit code 1

 
Marshal
Posts: 25467
65
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Zulfi Khan wrote:generate1000_5digit_RandomNum



Zulfi Khan also wrote:genrate1000_5difit_RandomNum

 
Zulfi Khan
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have corrected that typing error. I am having problem with passing 'n'



I am getting following errors:

/home/zulfi/PycharmProjects/sort/venv/bin/python /home/zulfi/PycharmProjects/sort/20_5digitRandom.py
Traceback (most recent call last):
 File "/home/zulfi/PycharmProjects/sort/20_5digitRandom.py", line 19, in <module>
   objTestRandom.main(20)
 File "/home/zulfi/PycharmProjects/sort/20_5digitRandom.py", line 15, in main
   self.generate1000_5digit_RandomNum(n)
 File "/home/zulfi/PycharmProjects/sort/20_5digitRandom.py", line 11, in generate1000_5digit_RandomNum
   TestRandom.arr[i] = num
IndexError: list assignment index out of range



Somebody please guide me how to correct this argument passing problem.

Zulfi.
 
Marshal
Posts: 7602
521
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Zulfi Khan wrote:I am getting following errors:



Zulfi Khan wrote:I am getting following errors:



Zulfi Khan wrote:Somebody please guide me how to correct this argument passing problem.



Don't be a code spectator. Read error messages carefully, line by line, analyse them, try to make sense out of them, go back to code, look at it, try to understand once again what each line of the code does, go back again to an error message... Try.

Most of the time you learn when you think harder than you'd want.
 
Zulfi Khan
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have created the whole code on my own. I am trying but I can't understand the concept of paramter passing.

I am trying but how much time I can spend on it.

I don't have infinite time.

Zulfi.
 
Paul Clapham
Marshal
Posts: 25467
65
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's the error message you need to pay attention to:

File "/home/zulfi/PycharmProjects/sort/20_5digitRandom.py", line 11, in generate1000_5digit_RandomNum
  TestRandom.arr[i] = num
IndexError: list assignment index out of range



Look at the line of code which that error message refers to. Next, read the error message which tells you what the problem is.

One other thing: it looks like you already decided you have an argument passing problem. Making assumptions about problems can cause you to be blind to the actual problem.
 
Zulfi Khan
Ranch Hand
Posts: 159
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for your update.

I thought I created an unsized array, but actually its an empty array.

So I can't use indexes with it.
God bless you.

Zulfi.
 
Can you hear that? That's my theme music. I don't know where it comes from. Check under this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic