Introduction to Linux
- If you are using the lab machines, need to switch to the Linux operating system
- The windows machines on campus do not have Python
- The computers in our classroom and in the first floor lab can boot into Windows or Linux
- Restart the computer and use the arrow keys to select Ubuntu
How to Think Like a Computer Scientist
- Open a web page and go to the daily schedule
- Note, your reading for the next class is listed here
- The top of the course web page has a link to the textbook
- Select ‘How to Think Like a Computer Scientist’ from the ‘Useful Info’ menu
- Can modify and run programs in the book
- There are questions at the end of each section, answer them to test if you undertand it before coming to class
- You can ask questions at the beginning of class, or email me questions if you are too shy to speak up during class
- Or even better, schedule an apointment to see me
- If you just want to write some code, use the book’s Scratch ActiveCode
- Click on the magnifiing glass in the navigation bar at the top and select ‘Scratch ActiveCode’
Turtle Graphics
Let’s write our first program
import turtle turtle.forward(100)
- Click run
- It draws a line
- This is similar to the Foos, you are giving commands to the computer
- In this case, you are commanding a tutle (the arrow) to move around the screen
- The turtle draws lines whenever it moves, so you can use it to draw pictures.
- Change the number and you change the distance the turtle moves
- Note, the turtle always starts in the center and moves to the right
You can change the direction the turtle moves with
turtle.left
andturtle.right
.import turtle turtle.left(90) turtle.forward(100)
- This is similar to the Foos, the commands are a sequence, in this case from top to bottom
- Note, the order matters
What happens when you switch the order?
import turtle turtle.forward(100) turtle.left(90)
- Can also move the turtle without drawing a line with
turtle.up
andturtle.down
- Also note, the
import turtle
at the top is necessisary - Try removing it, and you get an error
- The error gives you some information about what went wrong
- It tells you that it doesn’t know what turtle is and on what line
Some other common errors
- don’t forget turtle.
- don’t forget the parentheses
- don’t misspell the commands (or turtle)
Lab
- Work with a partner
- One computer for two poeple
- Both partners actively contribute to every bit of code written