Girl Develop It is here to provide affordable and accessible programs to learn software through mentorship and hands-on instruction.
Some "rules"
Terminal | A program that has a command line interface and issues commands to the operating system. |
Python Shell | A command line program that runs inside of the terminal, takes Python code as input, interprets it, and prints out any results. |
Text Editor | A program that opens text files and allows the user to edit and save them. (Different than a word processor). |
Linux | Gedit, Jedit, Kate |
MacOSX | TextMate, TextWrangler |
Windows | Notepad++ |
All | Sublime Text, Vim, Emacs |
Let's setup our computer for Python programming
[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27", "User")
Open up your terminal and type 'python'
Follow along with the examples in the slides. Type them in!
Feel free to explore as well. You will not accidentally break things
3 + 4
2 * 4
6 - 2
4 / 2
a = 2
b = 3
print a + b
c = a + b
print c * 2
a = 0
a = a + .5
print a
a = 'Hello '
b = 'World'
c = a + b
print c
a = "Spam "
b = a * 4
print b
a = 'spam '
b = 'eggs'
c = a * 4 + b
print c
a = 4
print type(a)
print type(4)
print type(3.14)
b = 'spam, again'
print type(b)
print type("But I don't like spam")
print "Spam" - "am"
a = 'Spam and eggs'
print a / 'hashbrowns'
print a / 6
# SyntaxError - Doesn't conform to the rules of Python. This statement isn't meaningful to the computer
4spam)eggs(garbage) + 10
# NameError - Using a name that hasn't been defined yet
a = 5
print b
b = 10
# TypeError - Using an object in a way that its type does not support
'string1' - 'string2'
There are also semantic errors. These are harder to catch because the computer can't catch them for us.
We'll practice what we've learned in the shell
Review the slides on your computer and practice entering any commands you didn't fully understand before
Ask the teacher or a TA for any help
Try each of the following commands in turn:
Command | Short for | Description |
---|---|---|
pwd | Print working directory | Displays what folder you are in. |
ls | List | Lists the files and folders in the current folder |
cd | Change directory | Change to another folder. Takes the folder name as an argument. 'cd ..' goes up a directory |
cat | Concatenate | Prints the contents of a file. Takes a filename as an argument |
We need a folder to save our work in.
The ->'s below indicate the expected output of the previous command.
pwd
-> /home/username
mkdir Projects
cd Projects
mkdir gdi-intro-python
cd gdi-intro-python
pwd
-> /home/username/Projects/gdi-intro-python
Now that the folders are made, we only have to use 'cd Projects/gdi-intro-python' in the future.
Open sublime text.
print 'I am a Python program'
To obtain user input, use 'raw_input()'
Change the class1.py text to the following and run it again
input_value = raw_input("Enter a radius:")
radius = float(input_value)
area = 3.14159 * radius ** 2
print "The area of a circle with radius " + input_value + " is:"
print area
N.B. - The user's input is a string so we use float() to make it a number
Write your own program that uses raw_input and does something else with the value
You can use float() to treat the input as a number if you need a number, or use the input directly as a string