Learning python

Started by
15 comments, last by Zaris 18 years, 7 months ago
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?
Advertisement
Unix and BSD are OSes (and your post makes it sound like you don't use them, so you can probably skip that). UTF is a character encoding. I don't know what BOM is. Maybe you meant DOM? Anyway, those are all things that you shouldn't need to get into for a while.
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!
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]
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.
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.
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').
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
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?
Caps are allowed, but, as has been said before, everything is case sensitive so you'll need to be careful.

This topic is closed to new replies.

Advertisement