-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExamples
59 lines (47 loc) · 1017 Bytes
/
Examples
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
### Getting Started ###
print('Hello World')
# advanced
print(5 * 'hello ')
### Reading Input ###
name = input('What's your name?')
print('hello ' + name)
# advanced
import random
r = random.randint(0,10)
print(r)
guess = input('Try to guess a number: ')
while int(guess) != r:
guess = input('Guess again! ')
print('You got it! The answer was ' + str(r))
### Conditionals ###
if temperature > 100:
print(‘What a hot day!’)
elif temperature < 0:
print(‘Brrrr!’)
else:
print(‘Just right!’)
### Python with Turtle ###
import turtle
tiny = turtle.Turtle()
tiny.pendown()
tiny.color("red")
tiny.forward(100)
# other helpful turtle functions include
tiny.left(90)
tiny.pinup() # stop drawing
tiny.goto(90, 90) # specific x, y location on the screen
# Loops
#long code:
tiny.forward(100)
tiny.right(90)
tiny.forward(100)
tiny.right(90)
tiny.forward(100)
tiny.right(90)
tiny.forward(100)
tiny.right(90)
#shorter code:
tiny.color("blue")
for i in range(4):
tiny.forward(100)
tiny.right(90)