Lesson 2 – Challenge Questions

Challenge 2.1

Objective

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

Hints

  • 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

Solution

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

Objective

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.

Hints

  • 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

Solution

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

Objective

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)

Hints

  • 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