473,395 Members | 2,468 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,395 software developers and data experts.

kid wants to know more about color on the screen

Dear Group,

My son who is in grade 7 has *just* started going through the book "Python
for the Absolute Beginner" by Michael Dawson. He and I have no programming
experience. He is beginning this on an old win 95 computer with Python 2.2 I
think.

He is getting a bit frustrated with color coding.
For example in Chapter 2 page 18 and 19 Mr. Dawson describes a more fancy
way of printing "Game Over" on the screen. According to *him*...

When I type the command: print "Program 'Game Over' 2.0"
print \

Instead of getting the second "print" to turn orange, like it's supposed to
when you type in a command, it just stays black. And when its time to
actually run the program, Python just prints out Program Game Over 2.0
instead of the fancy large text like that is shown in the book.

Later on he says that strings within quotes will be green as expected and
then all of a sudden on the next line it will stay black :(. And when he
does a run script there will be a syntax error as Python wont recognize this
'black' string but then on another occasion the 'black' will run ok :(.

I am sure my inquiries are quite vague but I am trying to piece together
some of his 'groans and grunts' :(.

Any suggestions or other info you need from him?

Thanks for your advice.

Jack
Jul 18 '05 #1
6 1576
On 2004-06-12, Doug Mitchell <jm**@SsYyMmPpAaTtIiCcOo.ca> wrote:
Dear Group,

My son who is in grade 7 has *just* started going through the book "Python
for the Absolute Beginner" by Michael Dawson. He and I have no programming
experience. He is beginning this on an old win 95 computer with Python 2.2 I
think.

He is getting a bit frustrated with color coding.
For example in Chapter 2 page 18 and 19 Mr. Dawson describes a more fancy
way of printing "Game Over" on the screen. According to *him*...

When I type the command: print "Program 'Game Over' 2.0"
print \

Instead of getting the second "print" to turn orange, like it's supposed to
when you type in a command, it just stays black. And when its time to
actually run the program, Python just prints out Program Game Over 2.0
instead of the fancy large text like that is shown in the book.

Later on he says that strings within quotes will be green as expected and
then all of a sudden on the next line it will stay black :(. And when he
does a run script there will be a syntax error as Python wont recognize this
'black' string but then on another occasion the 'black' will run ok :(.

I am sure my inquiries are quite vague but I am trying to piece together
some of his 'groans and grunts' :(.

Any suggestions or other info you need from him?

It sounds like maybe you are using a "highlighting" text editor. That means
the text editor adds color depending on the syntax of the colored text.
For instance, if you have

print "Game Over"

in the editor, the word "print" might be blue because it is a python keyword
and the "Game Over" might be orange because it is a string.

It is also possible that the book is doing something similar and coloring
the different words to show more information about their purpose or meaning.

If you then run that program in the normal text terminal it would just print
out in whatever color the terminal happens to be (in my case green text on
a black background).

If you want to make the text a particular color, you would need to tell python
how to change the color, and that is going to take some more work.

You may want to join the tutor mailing list which is set up specifically to
help people who are brand new to python and/or programming.

http://mail.python.org/mailman/listinfo/tutor

Jul 18 '05 #2

"Doug Mitchell" <jm**@SsYyMmPpAaTtIiCcOo.ca> wrote in message
news:FM*********************@news20.bellglobal.com ...
Dear Group,

My son who is in grade 7 has *just* started going through the book "Python for the Absolute Beginner" by Michael Dawson. He and I have no programming experience. He is beginning this on an old win 95 computer with Python 2.2 I think.
Congratulations to both of you.
He is getting a bit frustrated with color coding.
This is a post-beginner subject that I think would best be skipped for now.
But I know, kids like color as much or even more than adults.
For example in Chapter 2 page 18 and 19 Mr. Dawson describes a more fancy
way of printing "Game Over" on the screen. According to *him*...

When I type the command: print "Program 'Game Over' 2.0"
print \

Instead of getting the second "print" to turn orange, like it's supposed to when you type in a command, it just stays black. And when its time to
actually run the program, Python just prints out Program Game Over 2.0
instead of the fancy large text like that is shown in the book.
I've have never seen the book so I can only give comments similar to
Harr's.
Standard Python by itself knows nothing of colors and fonts. The print
statement sends characters to the the file stream called stdout (for
standard output) which usually goes the the terminal and appears in
whatever font and color the terminal is set to. So Dawson had to specify
something extra to get extra control.
Later on he says that strings within quotes will be green as expected and
then all of a sudden on the next line it will stay black :(. And when he
does a run script there will be a syntax error as Python wont recognize this 'black' string but then on another occasion the 'black' will run ok :(.


Some program editors do something extra to get different portions of the
program displayed in different colors so the programmer can pick them out m
ore easily. In the one 'he' (Dawson or your son?) used, string literals
are apparently green. String literals denoted by a ' ' pair or a " " pair
may not contain a newline (carriage return to you probably), which is to
say, cannot continue across more than one line. So, if one types:

text = "Something to display
when the monster dies"

the editor might turn 'Something to display' green, but if it knows about
Python, it will leave 'when the monster dies' black because it cannot be
part of the string on the previous line. The black rather than green says
that something is wrong, and when you try to execute the above, Python says
SyntaxError.

Terry J. Reedy


Jul 18 '05 #3
"Doug Mitchell" <jm**@SsYyMmPpAaTtIiCcOo.ca> wrote in message news:<FM*********************@news20.bellglobal.co m>...
Dear Group,

My son who is in grade 7 has *just* started going through the book "Python
for the Absolute Beginner" by Michael Dawson. He and I have no programming
experience. He is beginning this on an old win 95 computer with Python 2.2 I
think.

He is getting a bit frustrated with color coding. .... Later on he says that strings within quotes will be green as expected and
then all of a sudden on the next line it will stay black :(. And when he
does a run script there will be a syntax error as Python wont recognize this
'black' string but then on another occasion the 'black' will run ok :(.


It sounds like you're using a syntax highlighting text editor, that
is, it displays code in different colors depending on whether it's a
keyword, a comment, a string literal, etc. This highlighting helps
make it easy to see syntax errors (code that's in the wrong color is a
syntax error), but it's not part of the *.py file itself, and
therefore doesn't affect the output of the program.

However, it is possible to print colored text in Python.

Under Linux, you can print "ANSI escape sequences" (Look it up on
Google) to your terminal. These are strings starting with the control
character '\x1B' that, when printed, change the color of the text, or
move the cursor, or even change the frequency of the beep you hear
when you print '\a' (you can use this to make Python play simple
music).

I don't know how to do it on Windows, but there might be something for
it in the msvcrt module.
Jul 18 '05 #4
da*****@yahoo.com (Dan Bishop) schreef:
Under Linux, you can print "ANSI escape sequences" [...]
I don't know how to do it on Windows [...]


Just use an ANSI device drivers for DOS/Windows.

(try googling for "ansi.com", "ansi.sys", "nansi.com", ...)

--
JanC

"Be strict when sending and tolerant when receiving."
RFC 1958 - Architectural Principles of the Internet - section 3.9
Jul 18 '05 #5

"Doug Mitchell" <jm**@SsYyMmPpAaTtIiCcOo.ca> wrote in message
news:FM*********************@news20.bellglobal.com ...
Dear Group,

My son who is in grade 7 has *just* started going through the book "Python
for the Absolute Beginner" by Michael Dawson. He and I have no programming
experience. He is beginning this on an old win 95 computer with Python 2.2 I think.

He is getting a bit frustrated with color coding.
For example in Chapter 2 page 18 and 19 Mr. Dawson describes a more fancy
way of printing "Game Over" on the screen. According to *him*...

When I type the command: print "Program 'Game Over' 2.0"
print \

Instead of getting the second "print" to turn orange, like it's supposed to when you type in a command, it just stays black. And when its time to
actually run the program, Python just prints out Program Game Over 2.0
instead of the fancy large text like that is shown in the book.

Later on he says that strings within quotes will be green as expected and
then all of a sudden on the next line it will stay black :(. And when he
does a run script there will be a syntax error as Python wont recognize this 'black' string but then on another occasion the 'black' will run ok :(.

I am sure my inquiries are quite vague but I am trying to piece together
some of his 'groans and grunts' :(.

Any suggestions or other info you need from him?

Thanks for your advice.

Jack


As previously mentioned... the author is not referring to the color of the
output of the code, but rather the color of the code itself.

If you are using python on a Windows machine then the way to get the text to
hightlight is to save it as a *.py file... like test.py. Without the .py at
the end the text highlighting will not work.

Once it is saved as a .py file... the following types of rules will apply.

# this entire line is red because it is a comment

"this text is green becuase it is a string in quotes"

print "Some stuff" <-- "print" is orange because it is a python keyword.

def this: <-- "this" is blue becuase it is the name of a function
I hope this helps.
Jul 18 '05 #6
Hi Doug, I am also using this text. On the whole I find it very very good.
I am looking at the pages you mention and it looks like you have not added
the rest of the code after the print \ statement ... there is a whole bunch
of code in triple quotes that follows, when this is included you should get
the correct syntax highlighting. Actually I did this exercise only last week
with 2 year 7 classes.
Your problems are common and you will soon get over them, wait till page 22
when you see escape sequences! .. realise all these things become old hat
very quickly.
regards
Darren Payne

"Doug Mitchell" <jm**@SsYyMmPpAaTtIiCcOo.ca> wrote in message
news:FM*********************@news20.bellglobal.com ...
Dear Group,

My son who is in grade 7 has *just* started going through the book "Python
for the Absolute Beginner" by Michael Dawson. He and I have no programming
experience. He is beginning this on an old win 95 computer with Python 2.2 I think.

He is getting a bit frustrated with color coding.
For example in Chapter 2 page 18 and 19 Mr. Dawson describes a more fancy
way of printing "Game Over" on the screen. According to *him*...

When I type the command: print "Program 'Game Over' 2.0"
print \

Instead of getting the second "print" to turn orange, like it's supposed to when you type in a command, it just stays black. And when its time to
actually run the program, Python just prints out Program Game Over 2.0
instead of the fancy large text like that is shown in the book.

Later on he says that strings within quotes will be green as expected and
then all of a sudden on the next line it will stay black :(. And when he
does a run script there will be a syntax error as Python wont recognize this 'black' string but then on another occasion the 'black' will run ok :(.

I am sure my inquiries are quite vague but I am trying to piece together
some of his 'groans and grunts' :(.

Any suggestions or other info you need from him?

Thanks for your advice.

Jack

Jul 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Otto Krüse | last post by:
Hello, I've made a small GUI program that connects with a MySQL database to collect information which is put on the screen. The database and the program are used for testing purposes so I...
27
by: xeys_00 | last post by:
I'm a manager where I work(one of the cogs in a food service company). The boss needed one of us to become the "tech guy", and part of that is writing small windows programs for the office. He...
9
by: Carlos | last post by:
I'm responsible for the content in a call center's intranet site. There are approximately 600 pages on 7 sub-webs. I have access to the sub-webs, but I don't have access to the root web or web...
9
by: Tom Dacon | last post by:
I have a little desktop application (it happens to be a Windows Forms analog clock) that's written in VB.Net (2003). I placed a shortcut in my Startup program group to start it up when I log on. I...
8
by: WindAndWaves | last post by:
Hi Gurus I am a newbie.... and I was wondering if it is possible to maximise a screen in javascript. right now, I use this code: A HREF="heritage.html" onClick="msgWindow=window.open...
4
by: EnderLocke | last post by:
I have a friend who wants to learn python programming. I learned off the internet and have never used a book to learn it. What books do you recommend? Any suggestions would be appreciated.
10
by: musosdev | last post by:
Hi guys I'm trying to migrate to VS2005... I've managed to do that, but realised I'd opened my web projects as file projects, and I'm getting the error about network BIOS command limit. ...
2
by: Simon Brooke | last post by:
This relates to my earlier questions about namespaces... When I use javax.xml.transformer.Transformer.transform( javax.xml.transform.Source, javax.xml.transform.Result) then, if I pass a...
0
by: Sundhas | last post by:
Hey! Scenario:What my project do right now 1. User Enters his Login and Password through his mobile phone and servlets contacts webservice of Authentication and user gets authenticated...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...

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.