Published using Google Docs
Sample Student Programming Reference Sheet
Updated automatically every 5 minutes

Sample Student Programming Reference Sheet

Handout A

Synthesize: Take a screenshot of important EduBlocks code or lines of code, copy and paste its corresponding Python code, and describe the features and purposes of each code or lines of code. 

Screenshot of the EduBlocks command/lines of code

Python code

In your own words, what does this code do?

variable = 0

This code defines a variable. In this example, the code is defining a variable called “variable” and it is equal to 0.

number_of_songs_in_playlist = input("How many songs do you want in your playlist?")

print(number_of_songs_in_playlist)

This code defines the number_of_songs_in_playlist variable by taking input from the user. The input from the user is printed.

number_of_songs_in_playlist = input("How many songs do you want in your playlist?")

print("number_of_songs_in_playlist")

This code defines the number_of_songs_in_playlist variable by taking input from the user. Only the variable name is printed, however, because of the quotes.

number_of_songs_in_playlist = "How many songs do you want in your playlist?"

print(number_of_songs_in_playlist)

This code defines the number_of_songs_in_playlist variable as "How many songs do you want in your playlist." The text definition of the variable is printed.

total = number_of_pop_songs+number_of_hip_hop_songs

print("The total number of songs on your playlist will be:")

print(total)

This code defines the total variable by concatenating the number_of_pop_songs variable and the number_of_hip_hop_songs variable. The print statement and both definitions of the variables are printed together side by side.

total = int(number_of_pop_songs)+int(number_of_hip_hop_songs)

print("The total number of songs on your playlist will be:")

print(total)

This code defines the total variable as the sum of the integer value of the number_of_pop_songs variable and the integer value of the number_of_hip_hop_songs variable. The print statement and the sum of the integer values are printed.

print("The total number of songs on your playlist will be: "+str(total))

This code concatenates text with the integer value of the total variable by making this value a string. The text is printed together with the value of the total variable.  

import random

This code imports the random library. This line of code is required whenever using any random functions.

playlist = ["song1", "song2", "song3", "song4", "song5", "song6", "song7", "song8"]

This code defines a list. In this example, the code is defining a list called “playlist,” which contains 8 elements titled “song1” through “song8.”

random_integer = random.randint(1,8)

This code defines the random_integer variable as a random integer between 1 and 8, inclusive.

print(playlist[random_integer])

This code uses the value of the random_integer variable to print an element from the playlist list. However, since the index of the elements start at 0, this code will never select the first element and will result in error if the random integer generated is 8.

print(playlist[random_integer - 1])

This code subtracts 1 from the random_integer variable. The element selected and printed now corresponds with the random integer value that was generated.

for i in range(5):

  print("What's up?")

This code creates a “for loop”. In this example, the question “What’s up?” is printed 5 times. Note that the statement is printed 5 times because 5 is the argument of the range in the for loop.

for i in range(turns):

  new_number += 2

  print(new_number)

This code prints an amount of statements that depends on the value of the turns variable. The sum of the value of the new_number variable and 2 is printed first. The next statement is the value of the previous statement and 2. This process repeats depending on the value of the turns variable.

number_list = []

for i in range(turns):

  new_number = int(input("Pick a

  number to add to the list:"))

  number_list.append(new_number)

This code allows the user to build a list of numbers. In this example, the list is initially empty and called number_list. The code uses the value of the turns variable to ask the user to input that amount of numbers to the list. The last piece of code adds, or appends, an element to a list. In this example, the value of the new_number  variable is appended to the list called number_list.

print("The second number in your list is: "+str(number_list[1]))

This code prints the text “The second number in your list is: ” concatenated with the second element in the list called number_list.

import math

This code imports the math library. This line of code is required whenever using any math functions.

hypotenuse_response = input("Do you know the length of the hypotenuse?")

if hypotenuse_response == "no":

This code uses an “if statement” to determine how to proceed. In this example, the user is asked if they know the length of the hypotenuse. If the response is “no,” the program will use the code within the if statement code to continue.  

hyp = math.sqrt(leg_1 * leg_1 + leg_2 * leg_2)

This code defines the hyp (hypotenuse) variable as the square root of the sum of the leg_1 variable squared and the leg_2 variable squared. In other words, it performs the Pythagorean theorem calculation for finding the length of the hypotenuse.

else:

This code is an “else statement.” This code is used to determine how to proceed when the if or elseif statements were not satisfied.

elif side_response == "b":

This code is an “else-if statement”. In this example the user has three choices, “a,” “b,” or “c,” and this code is used to tell the program how to continue if the user inputs b.

hyp = math.hypot(adj,opp)

This code calculates the length of the hypotenuse (hyp variable) by using the “math.hypot()” function, the length of the adjacent side (adj variable), and the length of the opposite side (opp variable).

My First Program: Using Trigonometry to Determine the Missing Sides of a Right Triangle

This program uses one of the sides of a right triangle and one of its acute angle measures to calculate the length of the other two sides of the triangle. More specifically, the program first asks the user for the angle measure of one of the acute angles. Then, the user is asked, with relation to the given angle, whether the length of the adjacent, opposite, or hypotenuse side is known. Based on the response, the program uses either cosine, sine, tangent, or the Pythagorean theorem to calculate the other two sides of the triangle.  

My First Program

My Second Program: My Lucky Number

This program asks the user to build a list of numbers and randomly chooses and prints one of these numbers. The program begins by asking the user, “How many numbers do you like (2 or more)?” in order to determine how many elements will go into the list. The user is then asked repeatedly to type in the different numbers that they like. The program finishes by randomly choosing and printing one of the numbers that the user had inputted.

My Second Program: My Lucky Number