# help with arrays and random.shuffle

Page 1 of 1

## 3 Replies - 5277 Views - Last Post: 05 March 2008 - 06:53 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=45090&amp;s=608576b20570932bd965ca2c17979c34&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 wokeup2sleep

• New D.I.C Head

Reputation: 0
• Posts: 3
• Joined: 04-March 08

# help with arrays and random.shuffle

Posted 04 March 2008 - 08:38 AM

im a beginner at comp science, and my prof is using python, which is totally new tom me i had a few questions with the program im writing, im having a few problems.

brief summary
i have to do a project where there are nine boxes filled with number 1-8, and 1 space is empty, the game needs to be scrambled, also all the moves need to be saved. the game can be paused anytime during thegame. the object is to move the numbers into the black spot till they are all in order.

the grid i have needs to contain variables so that can be moved by the players

this what i have and i know it is far off

```def board():
board = [1,2,3,4,5,6,7,8,9]

for x in range(0, 9):
print "|"

if(board[x]==9):
print "_"
else:
print board[x]

if(x==8):
print "|"
board()
```

when i run that it looks like this

|
1
|
2
|
3
|
4
|
5
|
6
|
7
|
8
|
_
|

and this is how i need it to look:

|1|2|3|
|4|5|6|
|7|8|_|

what am i doing wrong? also how do i use the random.shuffle() function so i can scramble the numbers?

help would be greatly appriciated...

also how would i save every move, also the random fuction isnt working so i can scramble the numbers.

i am probably doing everything wrong to make a game board, cause i need everything to to be interchanglable when the players wants to move and adjecent number to the blank spot, any help anyone???

thanks alot ahead of time

also i can't seem to import array or random
in addition my project is attached if anyone didnt understand what i needed to to do

#### Attached File(s)

This post has been edited by wokeup2sleep: 04 March 2008 - 08:43 AM

Is This A Good Question/Topic? 0

## Replies To: help with arrays and random.shuffle

### #2 Nykc

• Gentleman of Leisure

Reputation: 737
• Posts: 8,648
• Joined: 14-September 07

## Re: help with arrays and random.shuffle

Posted 04 March 2008 - 08:40 AM

Makes it easier to read.

### #3 wokeup2sleep

• New D.I.C Head

Reputation: 0
• Posts: 3
• Joined: 04-March 08

## Re: help with arrays and random.shuffle

Posted 04 March 2008 - 08:44 AM

thx for the tip

### #4 wokeup2sleep

• New D.I.C Head

Reputation: 0
• Posts: 3
• Joined: 04-March 08

## Re: help with arrays and random.shuffle

Posted 05 March 2008 - 06:53 AM

can anyone help me please???