Lesson 1 – Challenge Solutions

Challenge 1.1
def border_text(text_var):
     # Let's create our function

     # Take the length of the text and multiply it by "=" (the border)
     border = '='*len(text_var)

     # Print the border, the test, and then the border with separating lines


     return 0

border_text("Hello World")

Hello World
Challenge 1.2
# First, import the math library
import math

# The math library's sin, cos, tan, etc. functions
#  deal in radians so we need to convert degrees to radians
angle_b = math.radians(54)

# Let's find side c
# cos(54 degrees)=4 inches/c inches
# c inches*cos(54 degrees)=4 inches
# c inches=4 inches/cos(54 degrees)
side_c = 4/math.cos(angle_b)

# Now let's find side b
# sin(54 degrees)=b inches/side_c
# side_c*sin(54 degrees)=b inches
side_b = side_c*math.sin(angle_b)

# Okay, let's print everything out
print("Side a: 4 inches")
print("Side b: "+str(side_b)+" inches")
print("Side c: "+str(side_c)+" inches")
Side a: 4 inches
Side b: 5.505527681884694 inches
Side c: 6.805206466816319 inches
Challenge 1.3
# Used to prevent a link from the last_level and pascals_triangle
import copy

# Let's create our list and start it will 2 levels
pascals_triangle = [[1], [1, 1]]

# Let's create a while loop that will stop on the tenth level
while len(pascals_triangle) != 10:

    # We need a copy otherwise it will be linked to pascals_triangle
    last_level = copy.deepcopy(pascals_triangle[-1])

    # Okay, for our next loop, it's going to create the next level
    new_level = [1]
    while 1:
        if len(last_level) == 1:


[1, 1]
[1, 2, 1]
[1, 8, 28, 56, 70, 56, 28, 8, 1]
[1, 9, 36, 84, 126, 126, 84, 36, 9, 1]

Lesson 2 Challenge Solutions

Challenge 1.1

def find_factors(number):
	# Functions because why not?

	# Initialize out list
	factors = []

	# Starting from 1, let's test each number
	for curr in range(1, number + 1):
		# Taking the modulas, if there is a reminder,
		#  It's not a factor
		if (number % curr == 0):
			# We found a factor, add it to our list

	# We went through every number from 1 to the user's number
	# Return what we have
	return factors

# Ask the user for an input (and take the integer of the string that comes in)
usr_inp = int(input("What number would you like to find the factors of? "))
# Print out the factors
print("The factors of", usr_inp, "are:", find_factors(usr_inp))
What number would you like to find the factors of? 12
The factors of 12 are: [1, 2, 3, 4, 6, 12]
Challenge 1.2
from random import shuffle
from math import pi

def pi_finder():
	# Keeping trying until we find a suitable denominator and numerator
		# First: Take 9 digits, randomize the order, & create a number from it
		denominator_list = ["1","2","3","4","5","6","7","8","9"]

		# Multiple ways to do this, this take a list of numbers, and takes an
		#  empty string and adds each element from the list - finally taking the
		#  numeric value of the string using int()
		denominator = int(''.join(denominator_list))

		# Second: Take that number times PI (denominator times pi equal numerator)
		#		    and then take the integer of the value
		numerator = denominator * pi
		numerator = int(numerator)

		# Third: Check if it's 9 digits, and check if those digits are unique
		#		   from each other
		# Much easier to deal with strings at this point
		str_numerator = str(numerator)

		if (len(str_numerator) != 9):
			# Continue means reset from the top of the loop

		# Create a pool and remove each number as it is found
		pool = ["1","2","3","4","5","6","7","8","9"]

		for curr in list(str_numerator):
			# Take each number out as it is found
			if (curr in pool):

		if (pool != []):
			# If it is not empty, there are dups in the numerator

		# At this point all checks have passed, return the number
		return [numerator, denominator]

# Run the function
result = pi_finder()

# Print out the results
print("The numerator is:", result[0])
print("The denominator is:", result[1])
print("The approximation of PI is:", result[0]/result[1])
The numerator is: 613987452
The denominator is: 195438276
The approximation of PI is: 3.1415926530174674



Lesson 2 – Challenge Questions

Challenge 2.1


Create a script that will take a user input, find the factors of that number, and print those factors.


  • It would be sad if you don’t know what factors are, but here you go
  • Use a list to store the factors you have found
  • Use a loop to check each possible factor
  • Use the function input() to collect a user’s input
  • That input is going to be a string, turn it into an integer


Here is the possible output of a function:

What number would you like to find the factors of? 12
The factors of 12 are: [1, 2, 3, 4, 6, 12]

Challenge 2.2


Create a script that can generate a fraction consisting of 10 unique numbers on the numerator and 10 unique numbers on the denominator that can be a close approximation of PI. So, each number (1,2,3,4,5,6,7,9,0) can only be used once in the numerator and same for the denominator.


  • You will probably use random numbers (import random) for either the denominator or the numerator
  • Use a list for creating the random unique numbers
  • Also, add the math module, it contains PI math.pi (import math)
  • You will probably use loops
  • This is simpler than you think


This is one of the many answers that could be generated through a good script:

The numerator is: 2385140697
The denominator is: 759213864
The approximation of PI is: 3.141592652739018

Challenge 2.3


We have been given some file transfer data from the NOvA experiment. These data files contains a lot of information about file transfers for this experiment. We are going to take how many jobs started in one day. We will then plot this data in a histogram with the bin size being 1 hour.

Link to the data

Here is the header which has been removed from the csv file,

JobID,JobStartTime(unix timestamp),FileID,FileSize(byte),NodeName,FileProcessingTime(second),FileTransferTime(second),NodeType,FileTransferRate(byte/s)


  • Take a look at the matplotlib histogram script you did in the lesson
  • Most of the data in the data file for what we are trying to do is irrelevant, pay attention just to how many jobs were in a particular hour
  • To find this, you are given a jobStartTime which is a unix timestamp, lookup how to get an hour of the day from this timestamp, then count how many are in each hour

Lesson 1 – Challenge Questions

Here are a few challenges that you should be able to complete based on the knowledge you have currently.

Challenge 1.1


Write a function that takes a text string (i.e. text_var = "Hello World") prints it back out with a border above and below it.


  • You need to count the number of characters in a string, use the len(text_var) function
  • Use the equal sign (=) for the border
  • The function should create the same number of = characters as the number of characters in the string


Here are a few examples:

border_text("Hello World") # will return
Hello World

border_text("Hello Mike") # will return
Hello Mike

border_text("Hello") # will return

Challenge 1.2


Write a set of Python statements that can find the length of each side of this right triangle.


Given the following:

  • Angle C is 90 degrees
  • Angle B is 54 degrees
  • Side a has a length of 4 inches


  • Use the Math library
  • Use basic Trigonometry (if you need help, ask)
  • You will probably need to convert degrees to radians (there’s a function for that)

Challenge 1.3


Create and print Pascal’s triangle by showing 10 levels. Have each level’s list in one big list (i.e. pascals_triangle = [[1], [1, 1], [1, 2, 1], [etc.]]). You cannot just write [1,3,3,1] in your code, you must find it through an algorithm.

You can append a list after you have created it. For example,

pascals_triangle = [[1]]



Pascal's Triangle


pascals_triangle[0] # Should return
pascals_triangle[1] # Should return
[1, 1]
pascals_triangle[2] # Should return
[1, 2, 1]

# All the way to
pascals_triangle[9] # Should return
[1, 9, 36, 84, 126, 126, 84, 36, 9, 1]