Reading Questions
Quiz
Range
- We’ve already seen range with single input
- If we want different values for i, can write expressions to compute them
- For example if want to start at 1, add 1 to i
- There is an easier way, range has optional arguments
- If there are two arguments they are start and stop
- If there are three arguments they are start, stop, and step
New Lines
Can specify that a print statement doesn’t end in a new line
print("something", end=" ") print("something...")
- Whatever is inside of the quotes after
end=
will be used instead of a new line This is useful if you want to put everything a for loop prints on one line
for i in range(3): print(i, end=" ")
- Note, this will leave a space at the end of the last print statement and no new line
- Can get a new line with
print()
after the loop How can you get rid of the extra space?
Range Peculiarities
- What happens if you use a floating point number?
- What happens if you use a floating point number that represents an integer?
- What happens if you flip the start and stop values?
- What happens if you start and stop at the same value?
- What happens if you change the loop varible, inside of the loop?
More Turtle
goto
tell the turtle to go to an x, y coordinate- Where is the orgin?
- How big is the coordinate plane?
setheading
tell the turtle to turn to an orientation- useful when turtle code is mixing forward and goto commands