Sie sind auf Seite 1von 1

Cheat sheet: turning Scratch into Python

Try out your new text-based programming skills with these


awesome Python projects: rpf.io/startpython

INPUT LISTS

ask Which card did you pick? and wait hand


card = input('Which card did you pick?') 1 hand = ['ace',
set card to answer 2 'king',
3 'queen',
4 'jack',
OUTPUT 5 'ten']

say Hello World!


print('Hello World!')
say foo
print(foo) length: 5

SELECTION add nine to hand hand.append('nine')

if foo > 10 then


if foo > 10: delete 1 of hand hand.pop(0)
say foo is greater than 10 print("foo is greater than 10")
else elif foo < 10:
print("foo is less than 10")
if foo < 10 then
else:
LOOPS
say foo is less than 10
print("foo is equal to 10")
else
forever
say foo is equal to 10
while True:
change foo by 1 foo += 1

VARIABLES
repeat until foo > 10
while not foo > 10:
print(foo)
say foo
set foo to 10 foo = 10
bar = "some text"
set bar to some text

repeat 10
for i in range(10):
say hello print('hello')
foo = foo + 1
change foo by 1 #or
foo += 1

CONCATENATION
RANDOM
set foo to join hello world foo = "hello" + "world!"
set foo to pick random 1 to 10 from random import randint
foo = randint(1, 10)

Raspberry Pi Foundation, UK registered charity 1129409

Das könnte Ihnen auch gefallen