Skip to main content
gamedev.net
🔒 Locked

Learning python

Started by The Ice Master 15 replies 900+ views
Original Post
The Ice Master
The Ice Master
I decided to go with Python for my first language. I have been workin with it for about half an hour now, and its really fun! 1 minute into it I learned that typing in:
import sys; sys.exit()
will exit the program. I could just click the X, but thats cool too. ;) I kept reading, and I saw an example of an "if" statement, and tried to make one I made up.
the_world_got_blown_up = 1
if the_world_got_blown_up:
     print "We are screwed."
And after pressing enter twice, it said we are screwed! Heh this is great. :) I then learned for the if statement all I had to put was:
if 1:
I am learning slower at this point. It is talking about stuff like Unix, BSD, UTF, BOM, and stuff. Should I do something before trying to learn more so I can understand this? Or is this kind of stuff useless information that I should just skip?
The Ice Master
The Ice Master
Thanks. I also learned it was a calculator. It handled an incredibly complex simplifying problem in 1 second. (I just typed in about 6 lines full of numbers, multiplication, and division signs.)

*sigh*

Man I sound like a noob. Well, I am!
Arild Fines
Arild Fines
Quote:
Original post by Roboguy
UTF is a character encoding. I don't know what BOM is. Maybe you meant DOM?

A BOM is a Byte Order Mark. UTF-* text files can have them at the beginning to indicate what endianness the file has (and, of course, the presence of a BOM also tells editors etc they are indeed dealing with an UTF encoded file).

--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
SiCrane
SiCrane
BOM in this context probably means byte order marker for Unicode files. You should learn that stuff probably eventually, but if you just want to write a game as soon as possible you can probably skip those topics for now.
The Ice Master
The Ice Master
Ok, I am trying this variable thing now. (I guess you could call this a game - a very simple one.)

I have assigned the variables to numbers.

The variables are my 'characters', and the numbers are their body weight.

At the end, based on my logic (I never actually saw this was possible), I should be able to see how much they all weigh together on a scale.

idiot = 103unusually_fat_man = 609Me = 135Car = 2500

Those are my variables and their assigned numbers.

Now I have the next little piece of code:
all_of_us_on_a_scale = idiot+unusually_fat_man+Me+Car


Now when I run this through, I get the error:
Traceback (most recent call last):  File "<stdin>", line 1, in ?NameError: name 'me' is not defined


But it is defined! I defined it as Me = 135! Why does it pick on me?!

Pun intended.
Tyr
Tyr
Haha, it's refreshing to see this kind of enthusiasm!

Have you seen this tutorial yet: http://www.freenetpages.co.uk/hp/alan.gauld/ ?

It's a great ground-up introduction to programming, with a strong emphasis on Python; seems like it could be useful.

Keep up the good attitude, and I wish you the best of luck!

Edit: as for your problem, Python is case sensitive, meaning 'Me' is different from 'me'; make sure that you've been consistant in your capitalisation, because it looks like that could be the problem (interpreter output has lowercase 'm' in 'Me').
Fruny
Fruny
Look at the error, it is telling you that me is undefined. me and Me aren't the same thing. A good many programming language are case-sensitive. Python is one of them.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
The Ice Master
The Ice Master
I already had a look at that. I have them both as "Me". What else could it be?

Edit: I assigned the same thing to
me
, and put
me
as
us_on_a_scale
, and it worked. Are caps not allowed?
Tyr
Tyr
Caps are allowed, but, as has been said before, everything is case sensitive so you'll need to be careful.
Fruny
Fruny
If you do Me = 40 and me = 25, then you have two variables, me and Me. If you then do Me + me, the interpreter should print out 65.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
obi-wan shinobi
obi-wan shinobi
I've been considering experimenting with Python for a text-based game (or possibly something with PyGame if it's simple enough to get into) and looking through the docs, I couldn't really find anything about file I/O. How does Python handle writing/reading to a file? Or is it even necessary if AFAIK Python doesn't require recompiling for some changes to source code (but then what about save files, etc.)?

EDIT: Yes, Python can be used to make games. Check out www.pygame.org for info.
SiCrane
SiCrane
Quote:
Original post by The Ice Master
Can Python be used to make a game?


Of course.
SiCrane
SiCrane
Quote:
Original post by obi-wan shinobi
I've been considering experimenting with Python for a text-based game (or possibly something with PyGame if it's simple enough to get into) and looking through the docs, I couldn't really find anything about file I/O. How does Python handle writing/reading to a file?


http://docs.python.org/lib/bltin-file-objects.html

http://www.diveintopython.org/file_handling/index.html
Zaris
Zaris
Playing with python is fun and I think it a good language for beginners. Best of all it is open source. Most of the tools are free and full feature.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.