Fall 2020 – HONR268N
Entry #1 | 09/10/2020 – 09/14/2020
TL;DR
Your shell determines the format of your command inputs; read up on it online to find out more.
The terminal help function is very thorough, but I found that a google search with a dumbed-down explanation serves as a better primer for commands.
If you run a command and it seems to be unresponsive or you want to stop it for whatever reason, try ‘control + c’.
Don’t use ‘sudo’ on the cluster! You will get reported (oops).
What is my shell?
That depends. A shell essentially provides you with a means to communicate with your computer—tell it what to do. There are different shell types that give you different features which may sway your preference of choosing one over another. I have no clue what those are, but that’s ok for now.
Entering “echo $0” into my laptop’s terminal window returned “-bash”. This tells me that -bash is the current shell I’m working in. A useful command if I’m switching between shells and forgot which one I’m using.
Entering “echo $SHELL” tells me what my default shell is; “bin/bash”. This command tells me that if I open a new terminal window, the shell will default to -bash.
That changed when I logged into the cluster though. There, the shell defaults to -tcsh and it behaves differently from -bash.
Typing in “help” on the -bash shell my laptop defaults to actually wasn’t very helpful. If I want information on what certain commands do in that environment, then I need to type “info” followed by a space and then the command. That takes me to a separate screen which gives in-depth information on the command. It took me a bit to figure out how to exit that screen, but it’s done by hitting “q” on my computer.
On the other hand, typing a command followed by “--help” on the -tcsh shell while on the cluster does yield helpful information.
What does the ‘touch’ command do?
After my first try with the command, it seems to create a file within a directory (defaults to working dir.) without any extension with the name I specified, and the help function confirmed that. It creates an empty file if it doesn’t exist already. But it also updates the latest access and modification times to the current time if the file does exist. There are a bunch of arguments you can use (I think of them as modifiers) to do different things. Just to test one out I changed the date my file was last accessed and modified to the day the world was supposed to end.
It worked. But, it still shows the time the last change was made. Oh well.
Why do we include ‘.’ after the ‘find’ command?
From my first use, I think that the search only happens within the working directory. Otherwise it searches for the keyword everywhere within the home directory.
Not quite
Hmmm…
How do I get of here?...
How do I kill a command?
Control + c. Thanks, Zach & Aaron!
So, I think ‘find’—without a ‘.’—searches for what you specify for down the path from your working directory, but not up it.
What does the ‘*’ do?
It opens the search up to include anything following or preceding it or both depending on where you put the ‘*’. E.g. A search for ‘*ish’ would yield anything with ‘ish’ on the end, including ‘ish’ itself.
What does the ‘rm’ command do? How is it different from ‘rmdir’?
It removes files. It cannot remove directories. ‘rmdir’ can remove directories but not files.
Why should I never use ‘rm *’ on the cluster or anywhere else I care about?
I’m pretty sure it would remove all files that the user has access to. It might be confined to the working directory but I’m not willing to test that hypothesis.
What do ‘>’ and ‘>>’ do? How are they similar and different? Any dangers of using them?
‘>’ writes to the specified file. ‘>>’ also writes, but more specifically it appends the input to the end of the file. ‘>’ will overwrite data and replace it with the input, which could be bad if that is not the intent. ‘>>’ will keep the current data and simply add the input to the end.
What would happen if I ran ls -l > log.txt?
The file “log.txt” would be overwritten with the long list of information from the files in the working directory.
What are 10 useful linux commands and what do they do?
cat
It stands for concatenate and reads a specified file without risk of altering it.
alias
Allows you to name another command or set of commands and recall it.
The alias dies with the terminal window you created it in.
It didn’t work at first.
chmod
Changes the permissions of a specified file or directory according to a 3 digit input.
chown
Changes the owner of a specified file or directory
Don’t use ‘sudo’ on the cluster!
df
Displays disk size
ping
Exchanges packets of information with a specified IP address to verify there is communication between the device and mine
ps
Displays current processes that are running
w
Lists users who are currently logged in.
grep
Searches for a pattern, or term, in files
kill
Hard-stops a process according to the process ID
I haven’t had to use this one yet but I imagine it could be useful
Control + c
Aborts the command you just issued
————————————————————————————————————————————————————————————————————————————————————————————
Entry #2 | 9/16/2020
EMACS
Using the ‘emacs’ command was relatively simple while using the ‘-nw’ modifier. However I had issues with the GUI.
Here was my first attempt—using ‘-nw’
It worked fine.
I was going to demonstrate how it didn’t work with the GUI, but now that I was going to log the error of course it’s working.
When it wasn’t working, my issue was that the GUI was unresponsive to any inputs—text or clicks. In fact, the file would open empty despite the fact there was already text in it. I saw that some of the icons I had hovered over would randomly appear to respond. No matter how long I waited though, there would be no sign of inputs working. My suspicion is that during class I was using a lot of bandwidth with Zoom since I saw my video lagging. Now that I’m not on Zoom it’s working just fine. Both times, I accessed the GUI through Terminal and had XQuartz running.
Which leads me to the next point. XQuartz is necessary, but only for the remote GUI access.
Here’s what I saw when it was working.
All the buttons were working, I could edit the file, no issues.
————————————————————————————————————————————————————————————————————————————————————————————
Entry #3 | 9/20/2020
Shell Scripts
Write first shell script
I created my first shell script using the emac command and made edit in the terminal.
I tried running it, but it didn’t work at first.
To troubleshoot, I ran what the script was supposed to run manually. It ran just fine. So, I reasoned the issue wasn’t the contents of the script but probably an error in the command for running the script.
The issue was that I had typed “<>” around “test” and I should have just typed “test”.
I played around with find and modifying the script to do the same things as my find commands. For some reason “ls” wasn’t working how I thought it would.
Of course, it’s important to not confuse apostrophes ‘ with backticks `. Now that those errors have been fixed The script runs as intended.
It also becomes clear that the backticks are working because the relevant text changes color within the emacs editor. Whereas the text was yellow before—indicating a string, I guess—it’s now purple.
Write a script that searches and logs rogs results for a given input
I modified the first script after this. Deleted all the echos and and added in the line which prompts a search via find. Attempting to run the script without the tcsh command resulted in a “permission denied” response from the system. Using chmod to give me permissions with the -x modifier changed that.
The -x is for execute and it gave not only me, but all users access to execute my file.
I wrote the homesearch.tcsh script and realized that using the * didn’t work quite how I thought it would when I put it in the argument. To make it behave more predictably, I put it into the find command.
I got the search to run and log correctly, but I had to make it run 2 find commands in order to both display AND log. When I tried shortening it to one it only logged.
What is piping?
Piping takes the output of one command and “pipes” it through another command. In other words, it takes the output of the first command as the input for the second.
Here’s an example which uses ‘ls’ to list the contents of a directory and ‘wc -l’ to count the lines output by ‘ls’. In essence, this pipe results in outputting the amount of files in the directory to the console.
How to change strings in a .txt file
‘sed’ is a powerful command. It can substitute strings of characters in a variety of ways defined by the user. In the following example, the command substitutes the string “was” for “is” everywhere in the ‘hw3.txt.’ file
It worked
The rest of the text is cut off but the entire file seemed to be shown. I wonder how to return just the number of hits and their positions in the text...
Using -o returns only the search term and piping it through ‘wc -l’ returns the number of hits.
Using -n returned the line on which the hit was on.
———————————————————————————————————————————————————————————————————————————————————
Entry #4 | 10/1/2020
Muons and C++
Why do muons travel farthest in particle detectors?
I started my search in our class text. I found that muons are relatively heavy compared to other particles being physically detected post-collision in accelerator experiments.
The muon is two orders of magnitude more massive than the components of a proton, and by extension, much more massive than even protons and neutrons. A quick google search shows that a proton is made up of two up quarks and one down quark. It makes sense since that adds up to a +1 charge. We know from discussion in class, that the top quark is extremely unstable. So, I would assume that the lighter particles are more stable than the heavier ones.
The muon must sit in a nice sweet spot, be special in some way, or both since it doesn’t decay before going so far out. It has a charge so it will interact with magnetic fields. If it is heavier than other charged particles being detected, for a given velocity or energy, it should have a larger arc radius as it travels through its curved path within the CMS.
The lhc-closer.es website kind of confirms that since it explains that the more energy a particle has, the shallower the curve of its arc through the detectors is. Muons are in fact special in some way because they can travel meters through iron without interacting, according to CERN’s CMS site.
Running first C++ script
First, I created the script, main.cpp, in emacs. Then, I ran it with g++ and had the contents of the script read with ./a.out.
What’s going on under the hood?
Using g++ -dumpspecs showed me that I was using v4.4.7
...
I used cat on a couple of math files in the bits folder
It looks like the trig functions above are composites of other functions.
More C++ scripts—simple calculators, T/F, and loops
The first run of my second C++ script resulted in some error. I debugged it by using cat and comparing the first script, which I knew was error free, with the one that was having issues. The error description gave me a clue that I had mistyped something. Sure enough I had omitted an ‘l’ (lowercase “L”) after ‘end’ on the first line after main().
Example three had an error in it to begin with, it was missing a set of quotation marks.
But before running, I fixed that and it went without any hiccups.
The ++ and -- operators add 1 and subtract 1, respectively. It makes no difference if they are before or after the variable. I guess it’s called C++ because adding 1 and subtracting 1 in this simple manner must be frequently used. Just a guess though.
Example 4 went well, too.
Example 5 was a while loop
For the for loop exercise, I wrote it without testing what was on the hw page first. I got the same numbers but in very different formats. At first, I thought is was because I had ‘endl’ in a spot and that removing it would solve the discrepancy, but it’s definitely a bit more than that.
...The hw code returned this:
After removing the ‘<<endl’ after ‘m’, this is what I got:
Success! After playing around with it a few times it worked. This is the condensed “for” version of the hw’s “while” loop.
——————————————————————————————————————————————————————————————————
Entry #5 | 10/8/2020
C++: Logic, Pointers, and Loops
Logic
I tried out the first script under the logic heading, it only printed out ‘n = 10’. I tried changing the parameters a bit to see if it would actually decrease n, but since ‘return 0’ was a bracket too high, it stopped the loop before it got a chance to run again. After moving ‘return 0’ down a line, it worked as expected per my changes. I set n = 15 to begin with, then flipped the inequality on the if statement and changed it to 10 so it was ‘if (n<10)’.
After moving ‘return 0’ down a line:
I guess I should mention that running the original script the way it was yielded a never ending spew of “n = 10” since the way the logic statement was set up would never modify n.
Pointers
The pointer script ran just fine.
Just for fun, I tried making ‘p’ a double pointer to see what would happen. The compiler told me that it couldn’t be done.
It was surprising to see program 1 run and not switch j to 5 when i was switched. I guess it goes to show that a variable will hold its value even if the value is set to another variable. I’m guessing one would have to set j to i again to have it update the change.
Yup. I changed the original script’s j = 1 to j = i and sure enough…
Ok this is beautiful! Of course program 2 shows how to do it. By pointing to the variable i’s address, we can always get the most current value instead of having to reset j everytime like in the previous example. Mind blown.
The new pointer example was interesting. We can essentially set a space of memory to a value without even assigning a variable in the way we’ve been doing it. ‘p’ is the variable for the memory address but not for the value. From here we could set a variable equal to that value after the fact. Very interesting!
My pi pointer took a bit to get right, but I figured it out. The main issue I had was that I was trying to put the value of p1 into the pointer p2 without using ‘new’ and got an error saying that double can’t be converted to double*.
When it ran correctly:
Computing
Write a small C++ code that shows examples of if and while logic statements.
For my loop example I created an outline of what could be a “Voyage into Space” simulator. I found the altitudes of our atmosphere’s layers and made the program print out statements according to the height. After a bit of fine tuning, it worked!
The biggest issue I had was that I didn’t use the logic statement correctly. Instead of ‘==’ I was using ‘=’ which made my program get stuck in my first ‘if’ loop. At first, I thought it was stuck because ‘x’ wouldn’t increment in that loop so I added ‘x++;’ at the end of each if and else if loop. Turned out that wasn’t necessary since if the ‘if’ statement were true, then that block should finish and then the program should move on. I forgot a bracket but the compiler easily pointed that out.
Alter the script given below so that it outputs the list of files that were updated within the current month.
This problem took surprisingly long to complete and ended up being super simple to write. I just had to take off everything that didn’t include the month and the search. To convert the month to a useful format I use ‘+%b’ in the ‘date’ function and that was basically it. I ended up with this:
Which output this:
To make sure it actually worked, I compared it to:
______________________________________________________________________________________________________________________________________________________________________
Speed of light, Phase and Group Velocity, and Speeds Higher than c
The speed of light in a vacuum is the constant c. This is the speed we refer to when referencing "the speed of light" in equations, concepts and discussion regarding reference frames in special relativity and the like—299,792,458 m/s.
When two waves interfere, they can produce a wide variety of "new" waves. Two waves of the same frequency, amplitude and on phase with each other will create an identical wave with double the amplitude but the same as their original components otherwise. If they were 180º off phase with each other, then they would cancel out. If they are traveling in opposite directions, they could create standing waves which would stand still over time. But a special case is where two waves are traveling in opposite directions at ever so slightly different frequencies. The resulting interference would create apparent pulses traveling much faster than either of the component waves. This screenshot taken from Michael Richmond's page on phase and group velocities demonstrates the effect.
If the waves are light waves, the resulting phase velocity—movement of the green dot over time—can actually be faster than light. The group velocity—movement of the magenta dot over time—will not however. There are special conditions for this phenomena that I'm not 100% sure of. From what I gathered, this can happen in a 'waveguide'. So maybe that means a wire, fiber optic cable, some other thing? I'm not sure. But I also found that this phenomena doesn't really mean much physically since the wave's energy is not traveling faster than c. It's just a mathematical representation of interference
Raymond Rumpf and Gifuni Angelo provide answers in regarding a question on the topic posted on ResearchGate.
So there you have it. Speed of light in a vacuum is still c and nothing else can travel faster.
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
Entry #6 | 10/23/2020
Intro to ROOT and C++ Arrays
C++ Arrays
The first two programs seemed identical to me so I’m not sure if I’m missing something or not, but running either resulted in the following:
How are elements distributed in columns and rows?
Essentially, what is happening is that a matrix is being created. In the first loop, ‘ii’ is a matrix of 3 rows by 1 column, with its elements being 1, 2, and 3 in that order. ‘j’ is the variable which specifies the element to be returned with each iteration of the loop. Here is a visualization of the ‘ii’ matrix:
The second loop has ‘LL’, a 2 by 3 matrix, being cycled through with both ‘j’ and ‘k’:
You can, and in some cases should, use braces to specify rows and columns. Find a simple example on google.
Ex: int x[3][4] = {{0,1,2,3}, {4,5,6,7}, {8,9,10,11}};
Link: https://www.geeksforgeeks.org/multidimensional-arrays-c-cpp/
Try removing this and see how the result changes. What does the & do?
It no longer generates random numbers after removing the ‘&’. The ‘&’ serves as a reference indicator. Instead of creating a new ‘int’ it references one that is already there.
Show how we get to this number?
2^(8n) - 1 = Largest integer that can be stored with n bytes.
That is because each bit has 2 possible values, each additional bit increases the amount of data which can be stored exponentially because this is a permutation problem. There are 8 bits to a byte. For example, if you have 2 bytes, that’s 8 bits times 2 which equals 16.
So, 2 represents the possible values for each bit, raised to 8—the amount of bits in a byte—times n, the number of bytes. You subtract 1 to account for the value of 0.
Put a cout statement into the code that makes it print the first 10 “random” numbers it generates. Run the executable a couple of times. What do you notice? (This is why they are called pseudo-random numbers.)
Try changing the seed (it should be odd and large). What happens then?
The numbers are the same if I enter the same number for loop iterations. After changing the seed, it changed the numbers but if I entered the same number of loop iterations, the results would still be the same.
Now try changing the number of times you call the random number generator from 1000 to other numbers (say, 10, 100, 100000, etc). What do you notice about the contents of the histogram?
The first numbers are the same. The histogram is different though. The higher the number of iterations, the more even the histogram is.
NOTE: there is an intentional mistake in the code.
It was a missing bracket. Don’t do what I did and put the bracket after the block of code ending at line 25. It will cause you to go down a path of never-ending errors which lead to despair and ruin, making you rethink your life permanently off-the-grid. The bracket belongs at the end of the file. The bracket belongs just before the block of code that draws the histogram, the program runs much faster than putting it at the end of the file.
Look at the .C file. This is root code, so you will run it on the root prompt as
root -l resolutions.C
Set N=1 and run it. From this "data", what would you guess the mass of the mother particle is? And, how far would you guess the true mother mass could be from this measured value?
I would say about 64 GeV and that the true mass is not far off from the measured value.
Now change N to 10. What do you find?
Now, I would say it’s between 40 and 130 GeV with the center being around 80 GeV, but there is a much larger room for error.
Change N to 100? What do you find?
The mass apparently centered around 100 GeV, though the amount of data to the left of the peak seems to be higher than that to the right. I think there is a smaller margin of error than the last run. Though the spread of data ranges from about 30 to 143 GeV, the peak at 100 gives a better indication of what’s going on.
Change N to 1000. What do you find?
The data is centered around 95 GeV with a range from about 22 GeV to 155 GeV. Again, the margin of error looks even smaller since the peak keeps getting closer to a certain energy.
Now open secretparameters.txt and change the first number in it to 1. Repeat with N=1,10,100,1000. What have you learned?
After stepping back for a bit and reexamining the scenario, it seems like the first number in “secretparameter” is the mother mass, and the data is randomly generated from there with resolution errors included in the simulation.
Summaries of Paragraphs in Higgs Paper
P1: There are a bunch of interactions SM predicts and force carriers for each kind of interaction. But the weird thing is that W and Z bosons of the weak force have mass and the photons of the EM force have no mass. How can that be even when we have a unification of the two forces: electroweak.
P2: Development of scalar fields helped derive the W and Z masses. Without any theory it was hard to predict the Higgs mass but rough calculations guessed it should be below 1 TeV. Experiments narrowed it down to the range of 120-135 GeV.
————————————————————————————————————————————————————————————————————————————————————
Entry #7 | 11/13/2020 - 11/18/2020
MadGraph and 3D Display of CMS Events
SCP—Secure copy
It was handy to learn how to upload local files to a remote server with scp. In order to do that, one simply uses the following command in a local terminal window:
scp source/directory/file.ext username@org.xyz:/destination/directory
You’ll be prompted to enter a password for the username account. If all goes well the file will be transferred.
Below is the example where I copy the ‘lhe2root.py’ file from my Downloads folder on my Mac:
You can see that after the transfer was completed, I could run ls in the destination directory I specified and there the file was!
Issues with MadGraph
One issue with MadGraph was that the version available from the download site is too updated to work with the default python on the cluster. For compatibility’s sake, copying the MG5_aMC_v2.2.3.tar.gz file from /home/HONR268N/SIMULATION into the MC… folder was the way to go.
Another problem I ran into was forgetting to use “cmsenv” before running the subsequent steps to generate the pp → ttbar processes. Everytime we use MadGraph or ROOT we have to use “cmsenv” prior, otherwise some issues will arise. In this case, I had an error when trying to generate the MG5 run that said Fortran compiler could not be found.
The third problem now is that I cannot successfully open the “converted” root file ‘MY_FIRST_MG5_RUN.root’. However, I don’t think it even converted correctly because when running ‘unweighted_events.lhe’ through the lhe2root.py script, all I see returned to the console is “Problem with line:... Skipping… “.
Turns out this is not a problem, it’s how the program works. The real issue I had was that I was not following up with the root command: ‘TBrowser’ followed by a space and some variable, call it “T”. That opened up the root browser so that I could see the data.
After typing the commands, it all worked:
Write a brief description of major parts of the CMS detector. What are the physical dimensions of each part?
Beam pipe: A long vacuum chamber that runs along the entire circumference of the LHC’s 26km diameter loop. This pipe is the “highway” along which protons are energized and speed up in prior to colliding in a small section of pipe centered at the CMS experiment. It was difficult finding information on the beam pipe, in particular, but I found a design report saying that its diameter ranges from 50mm to 400mm. The report also says beryllium is the preferred material, which I believe is the case for the segment of pipe where the collisions take place, but that its hazards, price, welding constraints and more make it impractical for the entire length of the accelerator. Instead, the majority of the beam pipe is made of aluminum alloys or stainless steel. I also found a 2011 request to make the beam pipe diameter smaller, reducing it to 43.4mm. So, in that range.
Tracker: The tracker is composed of silicon of 3 barrel layers (which I believe the 2011 request mentioned above also planned to add a 4th layer) and 2 disks on the endcaps. These layers total to 66 million pixels, each pixel measuring 100 x 150 micrometers, adding up to a surface area of .99 square meters. There is also a set of silicon strip trackers arranged in 10 barrel layers and 12 disk layers. The total of both types of trackers add up to 198 square meters. They measure muons with 99% efficiency and also aid in tagging b-jets. The tracker is the section directly around the beam pipe.
Calorimeter: There are two calorimeters, the ECAL and HCAL. The ECAL is composed of 75,848 lead tungstate crystals which detect showers of particles that interact with the EM force—such as electrons and photons. Each crystal has a front facing cross section of 22 x 22mm and is 230mm deep. The HCAL is composed of interleaved brass and scintillator plates and is responsible for registering hadron showers of protons, neutrons and all other particles made up of quarks and gluons.
Solenoid: The solenoid generates an EM field of 3.8T within a diameter of 6m and length of 13m. It is a massive superconducting magnet which holds about 2.3 GJ at operating conditions. The solenoid’s field affects the trajectory charged particles follow after an event. The momenta of particles can be calculated because of the known EM field strength and particle trajectories. The immense strength of the field is required because of the speeds the particles travel at is so high.
Muon tracker: The muon tracker is the outermost layer and as the name implies, tracks muons. It can be broken down into 3 subparts: drift tubes, cathode strip chambers, and resistive plate chambers. The first two provide precise measurements on particle position while the third stage provides precise information on timing. These three are combined and interleaved with iron return yokes to provide information on the paths of muons.
Find how to change the display to show you a view along the beam pipe?
Select the x,y plane view:
Which color tracks are electrons?
Electrons are represented with green tracks.
Which color tracks are muon?
Muons are represented with red tracks.
Which color track missing energy is represented with?
Purple/Pink
How are jets depicted in this visualization?
Orange cones
Can you figure out if a track has clockwise curvature, it is +vely charged or negatively charged? (when looking at the x-y view, with x along the horizontal axis)
If a particle tracks with a clockwise curvature, it is positively charged.
Study at least 2 events from each category in the files available with the display and specify how many objects of each kind are seen in every event?
Event 1: DoubleElectron_Run2012C_0.ig:Events/Run_202016/Event_616969809
Electrons: 3
Muons: 5
Photons: 1
Jets: 54
Missing Energy: 1
Vertices: 14
Event 2: Hto4l_120-130GeV.ig:Events/Run_201707/Event_635670564
Electrons: 0
Muons: 4
Photons: 0
Jets: 48
Missing Energy: 1
Vertices: 12
————————————————————————————————————————————————————————————————————————————————————
Entry #8 | 11/23/2020 - 11/30/2020
Higgs and Z-boson Invariant Mass
wget—Quicker than scp
If you need to download something from online and it's accessible via a link you can use wget instead of downloading to your local computer then transferring to the cluster with scp.
What does this root command do?
Add new TLorentzVector el3, el4 for the 3rd and 4th lepton and set their pt, eta phi, mass
Add these two vectors to get a new vector TLorentzVector zCandidate2
Add the two vectors zCandidate and zCandidate2 to get a new TLorentzVector Higgs
Define a new histogram H_zz: TH1F* H_zz = new TH1F("H_zz", "ZZ candidate invariant mass", 200, 0, 300);
Fill the H_zz histogram with HIggs mass. (using Higgs.M() )
Write the H_zz histogram
Open the output file and paste the Z_ee and H_zz histograms in your HW file
————————————————————————————————————————————————————————————————————————————————————
Entry #9 | 12/2/2020 - 12/8/2020
Python and Machine Learning
Syntax, Variables, and Numbers
Run the "Zoo" code. What is the output you get?
I got 30.
Exercise: Using the pre-declared variables, calculate the area of a circle, and assign it to a new variable named 'area'. Print 'area' to the console.
Try to figure out why one works and the other doesn't.
Method 1 doesn't work because once 'a' is set to 'b' and the program prints 'b', it will print 'a's new value, which is still 'b'.
Method 2 works because 'temp' holds 'a's original value, so when the program prints 'b' it will return 'temp' which is 'a's original value.
Exercise: Using temporary variables, switch the following data so that it makes sense. Print the new variables to the console.
Exercise: Write a function that will round a number to 'n' digits. Test your function using a print statement. Make sure the print statement is outside of your function.
What do you see when you execute this code?
Exercise: Write a function that takes in two lists as arguments. Your function must first find the max of both lists. It must return the product ('*') of the maxes. Test your function by printing to the console.
What is the output of the above code?
Exercise: Using print statements, and built-in functions min(), max(), sum(), write some code that either evaluates to True or False.
For the assigned values of variables a and b, what is the output?
Exercise: Change values of a and b such that the other two conditions are met.
What is the output of the above code?
Exercise
Exercise: Write a function to determine if the absolute value of the minimum in a list is odd. If it is odd, print 'odd' to the console. Else, print 'even' to the console
Add the following lines one by one to the above code and add comments to explain what they mean.
Exercise: Final is between the two teams. Complete the function below to select the captain of the losing team and print to console.
Complete the function below to implement the Purple Shell's effect. Pass the list 'standings' into your function and print the updated standings to the console.
Exercise: Your lucky number is 7. You really like 7. You even like numbers divisible by 7 (do I smell a modulus operator?). Write a function that counts the frequency of numbers divisible by 7 in a list, and print that frequency to the console.
It's important to understand the instructions before coding so that the right program is written. Otherwise, you spend time writing something that wasn't asked for:
The correct program is as follows:
Exercise:
MatPlotLib and Numpy
WOW! This is awesome. This is a very simple, but very powerful tool I'm sure will come in handy.
Exercise. Google the functions used by the matplotlib and numpy libraries to get an understanding of the flow of the code. In the blank code space below, import the matplotlib and numpy libraries and make any plot of your own. Use the above examples and the documentation pages to help you.
Paste the output of the above code to your HW.
-------------------------------------------------------------------------------------------------------------------------END OF FALL 2020 LOGBOOK-------------------------------------------------------------------------------------------------------------------------