473,406 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Please Help! need help creating a matrix!

i need help to make a board such as this:

-----------Col 0--Col 1--Col 2
Row 0------1------1--------0
Row 1------0------0--------1
Row 2------1------1--------1

(Please ignore the dashes, they were uses to space things out)

where the user enters a number between 3 to 6
and this number will be distinguished as variable 'dim'

The board will be a square matrix of size dim x dim. The contents of
each cell in that matrix will be a 0 or a 1. The computer will populate the matrix with 0’s and 1’s
randomly.

how do u do this??
Nov 21 '08 #1
7 2590
Curtis Rutland
3,256 Expert 2GB
Please use [code] tags to preserve whitespace and indention.

MODERATOR
Nov 21 '08 #2
bvdet
2,851 Expert Mod 2GB
Have you attempted to code this yourself? If you would show some effort, others would be more willing to help.
Hints:
random.choice(0,1)
Create a list of lists using a nested for loop or list comprehension

Example:
>>> for i in range(3):
... for j in range (3):
... print i,j
...
0 0
0 1
0 2
1 0
1 1
1 2
2 0
2 1
2 2
>>>
Nov 21 '08 #3
boxfish
469 Expert 256MB
random.choice(0,1)
Better make that
random.choice((0, 1))
Nov 22 '08 #4
bvdet
2,851 Expert Mod 2GB
Oops! Thanks boxfish.
Nov 22 '08 #5
well its something liek this, i started it...

Expand|Select|Wrap|Line Numbers
  1. def createboard(dim):
  2.     import random
  3.     global x
  4.     global board
  5.     row = []
  6.     for i in range(dim)
  7.         row.append(random.randint(0,1)
  8.  
  9.     board = []
  10.     for n in range(dim)
Nov 26 '08 #6
Curtis Rutland
3,256 Expert 2GB
Please enclose your posted code in [CODE] [/CODE] tags (See How to Ask a Question). Code tags preserve indention and uses a monospaced font.

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [CODE] [/CODE] tags in future.

MODERATOR
Nov 26 '08 #7
boxfish
469 Expert 256MB
You'll need a for loop inside a for loop. The pseudocode should be more like:
Expand|Select|Wrap|Line Numbers
  1. For each row:
  2.     Create a new row.
  3.     For each element in that row:
  4.         Add an element to the row.
  5.     Add the row to the matrix.
Hope this helps.
Nov 26 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: duikboot | last post by:
Hi all, I'm trying to export a view tables from a Oracle database to a Mysql database. I create insert statements (they look alright), but it all goes wrong when I try to execute them in Mysql,...
3
by: Lodewijk van Haringhal | last post by:
I'am new with javascritping not with programming. Is there nobody who can help me with ths simple promblem? :) Please, please give me a hint. Please help me with this script. I have two lists in...
6
by: James Walker | last post by:
Can some one help I get an error of 'checkIndate' is null or not an object can someone please help. I can't work out why Thanks in advance James <form> <td height="24" colspan="7"...
0
by: Kurt Watson | last post by:
I’m having a different kind of problem with Hotmail when I sign in it says, "Web Browser Software Limitations Your Current Software Will Limit Your Ability to Use Hotmail You are using a web...
5
by: TrvlOrm | last post by:
Can any one please help me...I am new to JavaScript and I have been struggling with this code for days now and can't figure it out. I would like to get the Buttons to correspond with the action...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
13
by: Joner | last post by:
Hello, I'm having trouble with a little programme of mine where I connect to an access database. It seems to connect fine, and disconnect fine, but then after it won't reconnect, I get the error...
1
PEB
by: PEB | last post by:
POSTING GUIDELINES Please follow these guidelines when posting questions Post your question in a relevant forum Do NOT PM questions to individual experts - This is not fair on them and...
6
by: jenipriya | last post by:
Hi all... its very urgent.. please........i m a beginner in oracle.... Anyone please help me wit dese codes i hv tried... and correct the errors... The table structures i hav Employee (EmpID,...
5
by: tabani | last post by:
I wrote the program and its not giving me correct answer can any one help me with that please and specify my mistake please it will be highly appreciable... The error arrives from option 'a' it asks...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.