Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8922453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:50:17+00:00 2026-06-15T06:50:17+00:00

I have this code that creates a matrix filled with zeros. I want to

  • 0

I have this code that creates a matrix filled with zeros. I want to replace some of the zeros with a “sign” which is given when creating a snake object. I then want to replace the zeros in the matrix with my sign without increasing the total amount of elements in the matrix.

With my “growth” function in the snake class I want to make sure that only zeros is overwritten but I get the error:

ValueError: (1, 4) is not in list 

When I’m sure that position actually do exist! The error code is different each time I run the program since the cordinates are generated on random. Here’s my code:

class field:
 def __init__(self):

    self.table= [ [ "0" for i in range(10) ] for j in range(10) ]

  def printfield(self):
     for row in self.table:
            print (row)


Class snake:

  def __init__(self,sign):
    self.sign = sign
    self.x = random.randint(1,9) 
    self.y = random.randint(1,9)    

    field.table[self.x][self.y] = sign


  def growth(self, list, index, element):
    if list[index] != 0:
        return False
    else:
        field.table[self.x-v*b][self.y-v*c] = element


  def increase(self,p,b,c):                                               

        for v in range(p+1):
                self.growth(field.table,field.table.index((self.x-v*b,self.y-v*c)), self.sign) 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:50:18+00:00Added an answer on June 15, 2026 at 6:50 am

    You’re confusing your indices in the two-dimensional list with values in the list. The statement

    field.table.index((self.x-v*b, self.y-v*c))
    

    looks for a value of (in your given error case) (1, 4) inside of the list field.table, which is of course not there. What you probably want is accessing field.table[1][4]. You could just pass the tuple as a variable to growth and use its elements as indices for the list, or pass field.table[self.x-v*b] as the list to growth and self.y-v*c as the index to access on that list.

    Also, you are filling the list with "0"s but checking against 0 inside your growth function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this JavaScript code that creates a table, and puts in the rows
Hi I have been working on this code that creates a table with radio
I have this function in a Code Igniter model that creates a new video.
I have the this code that will create excel file and work sheet then
I have create a vcf file that contains contacts by using this code ContentResolver
I have this code that I've edited: http://pastebin.com/vrqHek6S I've put in comments where I
I have this code that runs but never stops. class A { public static
I have this code that reads from XML file. It gets five strings (groupId,
I have this code that suppose to place the marker by the latlng public
I have this code that where I would normally use one line: if (tableView

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.