Computer Science Canada Python,Part1 |
Author: | SS_198 [ Tue Jun 16, 2009 1:58 pm ] | ||||||||||||||
Post subject: | Python,Part1 | ||||||||||||||
This isn' so much of a tutorial as a basic command structure for python. I hope this little peice of information helps you out, i've been reading some python books and this is a bit of what i've learned so far using python. How To Run Python Programs Via Cmd prompt C:\program.pyc Begin Python: The first program we will learn the the "Hello World" program, basicly an output program. There are 3 ways to do so, each with there benifits but ill edit more later to explain better. Program1:
Program2:
Program3:
Now let's say you want to ask a question, so what you type is the following Program4:
A few things to sort out: # Means that everything after # will be ignored Okay now since we've writen our first programs let's move onto some more difficult stuff. Dictionarys Well To Store mass amount of information you can use dictionaries. A dictionary file looks somewhat like this in python > 3.0.1 Program6: Dictionaries. "Shopping List"
Program7: Loop + if statement
Program8:
|
Author: | Zeroth [ Sat Jun 20, 2009 10:51 am ] |
Post subject: | Re: Python,Part1 |
A few nitpicky details by the resident compsci.ca python guru(one of them anyways...)... You need to specify that this is python v3. In previous versions of python, print was not callable. As well, your use of input only gives strings, not numbers, in v3. You need to cast it, using the factory function int. I think you should introduce lists first, before dictionaries. Plus, you are doing a lot of list-specific functionality on dictionaries, like pop, push, update. I know they work, but the conceptual ideas should be introduced with the lists. For your dictionary program, you should use only dictionary-style methods, ie, has_key, dict[key] access, keys(), values(), etc. You did misspell dictionaries. |
Author: | SS_198 [ Sat Jun 20, 2009 11:20 am ] |
Post subject: | Re: Python,Part1 |
Zeroth @ Sat Jun 20, 2009 10:51 am wrote: A few nitpicky details by the resident compsci.ca python guru(one of them anyways...)...
You need to specify that this is python v3. In previous versions of python, print was not callable. As well, your use of input only gives strings, not numbers, in v3. You need to cast it, using the factory function int. I think you should introduce lists first, before dictionaries. Plus, you are doing a lot of list-specific functionality on dictionaries, like pop, push, update. I know they work, but the conceptual ideas should be introduced with the lists. For your dictionary program, you should use only dictionary-style methods, ie, has_key, dict[key] access, keys(), values(), etc. You did misspell dictionaries. Ya, i guess your right, but im mostly editing and adding when i have time and after i've tested each program > i was thinking about adding lists before dictionaries but i was a little lazy. >but ill be adding more information after i've edit my python notes the first post was very messy but ill add more once im finished reading // reviewing : books and notes, ill make more edits. thanks for input though. |