LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-14-2007, 04:43 PM   #1
tjyorkshire
Member
 
Registered: Jun 2007
Location: UK
Distribution: openSUSE 10.2
Posts: 138

Rep: Reputation: 15
python: "none"?


I'm currently learning python at the moment.
Ok, I wrote this:

Code:
#! /usr/bin/env python

# Initializes the board matrix
col1 = ["-","-","-"]
col2 = ["-","-","-"]
col3 = ["-","-","-"]
matrix = [col1,col2,col3]

# Prints current board
def printboard():
	print "   1  2  3"
	print "A ",matrix[0][0],"",matrix[1][0],"",matrix[2][0]
	print "B ",matrix[0][1],"",matrix[1][1],"",matrix[2][1]
	print "C ",matrix[0][2],"",matrix[1][2],"",matrix[2][2]

board = printboard()

print board
When i run it i get this:
Code:
   1  2  3
A  -  -  -
B  -  -  -
C  -  -  -
None
Why am i getting "None" appearing?
 
Old 08-14-2007, 04:48 PM   #2
rubadub
Member
 
Registered: Jun 2004
Posts: 236

Rep: Reputation: 33
Because your calling the 'printboard' function, which returns nothing... then printing it!
You probably want...
Code:
#! /usr/bin/env python

# Initializes the board matrix
col1 = ["-","-","-"]
col2 = ["-","-","-"]
col3 = ["-","-","-"]
matrix = [col1,col2,col3]

# Prints current board
def printboard():
	print "   1  2  3"
	print "A ",matrix[0][0],"",matrix[1][0],"",matrix[2][0]
	print "B ",matrix[0][1],"",matrix[1][1],"",matrix[2][1]
	print "C ",matrix[0][2],"",matrix[1][2],"",matrix[2][2]

printboard()
 
Old 08-14-2007, 05:35 PM   #3
tjyorkshire
Member
 
Registered: Jun 2007
Location: UK
Distribution: openSUSE 10.2
Posts: 138

Original Poster
Rep: Reputation: 15
hahaha! I just had one of those light-bulb-above-the-head-turning-on moments!

It was such a silly little mistake staring me right in the face!

Thanks for your help!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Displaying "MyComputer", "Trash", "Network Servers" Icons On A GNOME Desktop LXer Syndicated Linux News 0 04-02-2007 08:31 AM
Python "fast enough" for medium-sized network application introuble Programming 4 01-16-2007 10:22 AM
[python] print "\033[5;",x,"H=>" datbenik Programming 1 01-05-2006 05:12 AM
User "list" running process "python" TroelsSmit Linux - Newbie 2 02-22-2005 04:55 AM
Python compilation error, "module search path"etc.. mindfestival Linux - Newbie 0 05-31-2004 02:52 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration