Basic Python
Branching & Random
Looping, Lists & Strings
Functions & Files
100

THIS command can be used to get information from the user

input()

100

randint(1, 10) generates random integers between one and THIS

10

100

fruits = ['banana', 'apple', 'grape']

THIS is fruits[2]

grape

100

THIS keyword begins a function definition

def

200

THIS variable type, named after an English mathematician, is used to express True or False

Boolean variables

200

var = True or False;

THIS is the value of var

TRUE

200

Use THIS loop to repeat code a specific number of times (often used with lists or strings)

for loop

200

THIS is one benefit of using functions

Shorter development time

Simpler iteration and testing of sub-components of code

Less duplication of code

Programming solutions that are easier to maintain

300

x = 5

y = 9

x = x + y

x = 8

THIS is the value of x

8

300

SURPRISE PICO!

THIS line of code sets up a component at GP15 as an input

Pin(15, Pin.IN)

300

Use THIS loop to check a condition before repeating code

while loop

300

THIS mode is used to open a file and at text from the beginning

'w' or write

400

THIS command inserts represents a new line in a string or print statement

\n

400

THIS operator is used to check if two values are NOT equal

!=

400

Fill in THIS to print each letter in the string 'phrase'

phrase = "Hello"

for x in phrase:

 print(THIS)

x or f"{x}"

400

THIS is the keyword used to send information back from a function to the main code

return

500

THIS command forces the computer to exit the loop or branching structure at that point

break

500

x = False

y = False

if x and y:

    print('Option 1')

elif x or y:

    print('Option 2')

else:

    print('Option 3')

THIS prints on the screen

Option 3

500

for x in range(5):

    print(f"{x}")

The code prints THIS

0

1

2

3

4

500

def mystery(filename):

    with (filename, 'r') open as file:

        content = file.readlines()

        data = []

        for line in content:

            data.append(int(line))

    return data

the function does THIS

takes a file name as a parameter, opens and reads all information from the file to a list, converts each item in the list to an integer, and returns the list of integers

M
e
n
u