Class 10 – Start Pandas

Today we are going to start using Pandas (pdf=Pandas_Well_Data).

We are using part of a data set that looks at arsenic concentrations in Bangladesh.

VIDEO

MAKE SURE TO TAKE THE QUIZ!

Homework

Due Next Class (Monday February 26, 2024).

  1. Take the data from class today and plot depth on the y-axis and arsenic on the x-axis. I would use ax.scatter() and I would also use the fig,ax=plt.subplots() notation.  Because when you plot something versus depth you always want depth in reverse order or inverted so the 0 is at the top and the maximum is at the bottom.    Use ax. and some google searching to find out how to do it. But if you stop and think about setting ranges you can change your start and stop intervals.  Then the next step is to put the x-axis ticks on top and to put the label position on top.  then you can set the x limits (xlim) to get the plot so it starts at 0.  Also xlim could go from high to low. If something takes a list you add a [] inside the ().   luckily to make this plot there is more than one way to alter all the parts.  When searching for answers I would google something like “matplotlib switch axes direction”.  I usually add pandas or matplotlib to the search and it should show you options.

arsenic-depth

 

3.  Now the second graph is fancier.  Take the first graph and color the points as shown below.  Do this by calling scatter three times but only selecting the data you want to plot each time you call scatter.  Think about the boolean calls we did in class.  These are the arsenic concentrations I am coloring.  Get the first graph nice and this second graph becomes easier.    Do not copy my colors.  These are good colors for representing the points.  Choose three colors and three symbols of your own and see how they work. As a hint I would first do the less than 10 and then greater than 50.   Then you can do the 10-50 which needs an “and” of some kind.
arsenic-depth-color

 

Class 9 – Start Arrays

Overview

Today we are going to look further into arrays.  The link (pdf=TwoDArrays-2024).

Video

Homework

Due Wednesday February 21, 2024:

  1. Your are only allowed to add two lines of code to answer this question.  Take your code from today where you read in Brian.csv and plotted the array.  You can only add two more lines of code to your work from today to make the plot.   Using two lines of code and your slicing nomenclature add an exclamation point.  Remember in the file I had the background as 0’s and the writing as 1’s.  You need to at least make a third color!.  Then print it in a color of your choice using a colormap.  My answer is below. Both answers are perfectly correct.  I just wanted to add more color this year!  To make the lines crisp I turned off interpolation.  Here is the documentation. But in imshow you need to add the keyword argument interpolation=’none’ like we did in class.                brian

2.  For part 2.  Make a new csv file in excel and make it so you can print your name in more than one color.   So read in your file and make the plot.  By plot it I mean show your name like I show my name!   As a hint.  I made my csv file in excel and I made the rows and columns smaller or changed the zoom so I could see the pattern I was entering.  When saving a csv in excel using the ms-dos csv option seems to work the best.  When making the csv file name the csv file with your name.

3.  For the third part.  Make an excel file with one column for x-values and three columns for y-values.  Label each column. I would do ten or so rows.  So approximately ten values for the x-values.  For the y-columns make each distinct.  You can choose your own function or pattern (straight, curved, etc)  for the y-values.   But make sure each line is unique.  Now read in the file and plot the lines in excel and label the axes.   So you need to make an excel file and use it to plot three distinct lines.

For handing in make sure to hand in your notebook, your csv file for you name, and the excel file for your lines.

 

Class 08 – More Line Fitting

 

We have done some line fitting and  will do more (pdf=more-line-fit-2024).  Half the life of a scientist is taking data, plotting it, and looking for a correlation.  Plus I want to make sure you can do this in your sleep.  What we are adding now is we will start to read data from a file so we can handle much larger datasets.   Today we are going to read in an excel file into Pandas which is the python library for line fitting and fit a line.  We are going to look at GDP versus life expectancy.  A common dataset in sustainable development.  This is to the website where I got the  the data but I also put the excel file on GitHub.

 VIDEO

new website for videos.

NEW VIDEO NO QUIZ

Homework

Due Wednesday February 19, 2024 💙

1.  You need to find some data from the web or a paper.  It could be from a paper you have read.  It could be from another class.  Find data with at least 10 data points.  I would do somewhere from 10-50 points.  Do NOT use data with dates.  Dates are hard.  If you use time for an x-axis it should be hours or something similar but not months/days/years with slashes. We will learn how to do dates later in the semester.  All other data should work.

2.  Put the data in an excel file.  Add your name to the name of the excel file.  This way I will be able to differentiate and read all the files.

3.  Read in the excel file and fit a best fit line.  Remember to add a figure caption and all other parts of a figure.  Add the text box showing m,b,r,p values to the graph.  In the figure caption say if the result is significant.

4.  Make a new sheet in your excel file that is a copy of your data.   If you data had a significant correlation (p<0.05) change the data in the second sheet to make it not significant (p>0.05).    Then read in the second sheet but remember you need the sheet_name keyword.  Show the new correlation.  If your data had no significant correlation (p>0.05) change your data to make it significant.   Show this new changed plot with a best fit line, figure caption etc.   I want you to manually alter your data in a second sheet and use the new data.  Add the text box showing m,b,r,p values to the graph.  In the figure caption say if the result is significant.

5.  Make a third sheet in your excel file.  Change your data again but this time take your significant correlation and multiple the y-values by -1.   Now save that sheet as a csv file with your name in the title again so I can read it in when grading.   Read it in and show the best fit line, figure caption etc. Add the text box showing m,b,r,p values to the graph.  In the figure caption say if the result is significant. Now answer this question.  Hoes does the r-value, p-value, and r-squared value compare between when you the original data and the data when you multiplied by -1.  Be specific.

6.  Summary

  • one figure of best fit line with your data
  • one figure of best fit line where you altered your data to make either significant or non-significant
  • one figure of data altered by multiplying by -1 read in from a csv file.

7.  For handing in.  Hand in your notebook, excel file, and csv file.   The excel file should have three sheets in it.

DON’T MISS THIS NEXT PART!

8.  This part will also be graded for the final 10%.  As part of the class you have to comment on three of the lectures by using the comments section of the blog over the course of the semester.  You do not have to comment now.  You will comment as the semester proceeds.  Comments can be wide ranging but need to be designed to improve the teaching or the homework given how you learn.  Would you change the notebook?  Would you change the homework.  Is there a hint I should have given.  How can you help me improve your learning and future students learning.  Previous comments have already helped me to streamline the packets and homeworks.   But now to make it  fun you have to write an ipython script that randomly chooses your three classes.  You need to randomly choose 2 classes between classes 2 and 16 and 1 class between classes 17 and 23.  There are at least two ways to do this;  you could use numpy.random.randint or you could use random.randint.  my answer using numpy looks like

Brian will comment on classes  [15 12]
Brian will comment on classes  [18]

my answer using randint looks like

Brian will comment on class  15
Brian will comment on class  3
Brian will comment on class  21
 Remember since you are using a random number generator everyone’s answers should come out different!  If you get two of the same number re-run it to get 3 unique numbers!  Plus every time you rerun the cell your numbers will change!

Class 07 – Fit a line

Overview

We are going to explore more how to do some math in iPython and how to make some plots.  Today you are going to write your own program to get the best fit line (pdf=FitALine).  The equations are from Harris-‘Quantitative Chemical Analysis’ (Harris-fit-a-line) (pdf=Harris-fit-a-line).  I am going to give you the equation and then using numpy you will make it work.  Once it is working you will then go back and get your your KNYC and KLGA data and determine the correlation.   Do not look at the answers until you are done ( Fit a line answer.  Don’t look until done!  pdf=Fit a line answers) today.  Talk to your neighbors about turning equations into code.

VIDEO

Make sure to take your quiz!

Homework 6

Homework 6 Due Wednesday February 14, 2024

Repeated from last class.

  1. Don’t Forget you are supposed to be working on SoloLearn.  Go back and make sure you started it correctly!

THIS IS THE REGULAR HOMEWORK FOR MONDAY!

  1. You need to go and create a dataset and then fit a line to it.
    1. You should present a hypothesis, get the data, determine the fit.
    2. Your data and hypothesis can be anything and does not need to be “real”.  you can be creative.  You could interview friends to get data points.  You can search online.  You can make it as fun as you want. You can make something up!  But you need to state a hypothesis.  Have fun with it.
    3. You need at least 5 data points that you generate from your ideas and hypotheses.  Make it look good!  This is not about the data.  This is about the idea of presenting a hypothesis and fitting a line!  make it fun!  Be goofy!
    4. Once you have the data make the graph look professional.  Then you have to write a figure caption and summary sentences about your results in markdown.  This should all be in one ipython notebook with nice Markdown.
      1. For this I mean add a markdown cell below each graph explaining the result in a figure caption.
    5. The results should be presented from both your method for fitting a line and a python method for fitting a line.  This is redundant but make sure to do it!  Fit the same data twice to make sure you get the same result. You should make sure that your line fitting algorithm and the python algorithm give the same answer.
      1. For your method I mean where you did the math on your own.
      2. For the python method I mean linregress.
    6. The results need to be presented in the figure as a title or a text box.  I like the text box!

3.  My grading fit-a-line

Class 6 If/elif/else Statement

Today we are going to learn about If/elif/else (pdf=ifelif)statements.

If you do this work:

you will know if statements

elif you partially do the work:

you might sort of know them

else:

you won’t get much out of today’s lecture!

Some reading

If statements
http://www.tutorialspoint.com/python/python_basic_operators.htm
http://www.tutorialspoint.com/python/python_decision_making.htm
http://www.tutorialspoint.com/python/python_if_else.htm
But we need to know Boolean
https://docs.python.org/2/library/stdtypes.html

Video

Don’t forget the quiz on courseworks.

Homework 5

Due Next Class Wednesday February 7, 2024

    1. We are going to try a new website for learning Python. It is Sololearn and here is the link for the Python Course.   https://www.sololearn.com/Play/Python/ .  You will need to make a login for it.
      1. We will start by doing through Basic Concepts and Control Structures.
      2. You can go through and just answer the questions or also try things out.  It is up to you.
      3. I am just trying to get you extra Python Practice.
      4. This is Due on Monday October 10, 2022 (Courseworks had it correct).
      5. I can not track a class.   The picture shows what mine looked like when done.  
      6. Make sure the picture shows your login name and your name on your computer to prove it is yours.
      7. On the assignment in courseworks you will upload the screenshot.

Regular Homework

  1. Go back and find when you plotted the parabola and sin x.  These are really nice graphs that you made.
    1. Use input and if statements to ask the user if they would like to plot sin x or to plot the parabola
    2. If they choose sin x use an input statement to determine the number of pi’s they want to plot and plot the appropriate graph.  This way you can show many pi values.
    3. If they choose a parabola have them enter the a,b,c of the parabola.
    4. For example if I choose sin of x I could then choose 32.1 pi’s to plot.
    5. For example if I choose parabola I could then choose a=1, b=-5, c=0.02
  2.  You should have all your code in one ipython box so I can just run that one box, do my entries, and then see the plots.  if-statements grading rubric
  3. Remember to use input()
  4. To get an integer or float (remember to use them correctly, You need to choose when you think an integer or float is more appropriate) use input like
    1. a=int(input(‘please enter a number as an integer’))
    2. myfloat=float(input(‘please enter a number as a float’))

Class 1. Introduction and Central Park

Class 1-Introduction to the class and Python.

Why iPython?

Pick up Python from Nature

Before Class:

  1. Install Anaconda (see notes below and Watch Video).

Installing Anaconda

  1. WE ARE USING PYTHON 3 this year!
    1. goto https://www.continuum.io/downloads
    2. scroll down a bunch to where it lists operating systems. We are up to 3.9.x
    3. for windows download the 64 bit installer
    4. for macs download the command line installer.
    5. UPDATE Just do the installer.  If it fails then we can do the command line.
  2. ON YOUR COMPUTER
    1. On a Mac.  UPDATE Just do the installer.  If it fails we can do the command line.
      1. This is critical.  You need to do the command line installer.  I am updating the video
      2. this is the link for installing on macs.
      3. Install like above.  But to run I open terminal.  You can open terminal by typing “terminal” in the search icon.  Then at the prompt type “jupyter notebook”
    2. On a PC
      1. I run anaconda on my PC.  It has a quirk. Install it.  But then my launcher always crashes.  To work around.
      2. Instead of opening installer open the anaconda command prompt.  If you can’t open this, go to the file browser and open a new “Anaconda Prompt” window.
      3. once open type “cd /” to get to root directory.  This gives you access to all your directories on your hard drive.  I Can’t run from here.
      4. type “dir” to get your list of directories.
      5. change to the directory you want to use using cd and you are ready.
      6. now type “jupyter notebook”.
      7. You should have notebook now open in your browser
  3. ON THE MILBANK 222 MACS
    1. due to technical issues we can’t permanently install anaconda so we have to install it every class. the installer is on the root level of the hard drive.
    2. Google Anaconda Python
    3. Click on the MAC symbol and download 3.6
    4. Click on the Installer and then go through installation.
    5. Finding the launcher is tricky.
      1. Open Finder
      2. Goto the Macintosh
      3. Goto User->Student->anaconda and launch
      4. Open Jupyter Notebook.
      5. I will add pictures.

 

Goals For Class 1:

  1. In Class
    1. Download syllabus
    2. Fill in survey
  2. Complete the Central Park Notebook
    1. You should now have Anaconda with Python version 3.9  installed.
    2. this is the ipython  notebook (pdf=time-series-first-analysis_v2) to download and complete during the first class.   I will bring printouts to class. It is on github and in a pdf.
    3. Read the text and copy the examples.  In the blank cells try to figure out the code!
    4.  If you need to download the notebook right click on raw and say save as.  Then you have the notebook. If you get a .txt file ending change it it .ipynb
    5. Today’s goal is to slowly work through the notebook.  Take your time.  I gave us plenty of time.
  3. For Homework
    1. sign up for code.org   We are going to do 2 courses
      1. The first course is Anna and Elsa hour of code with id GLVSKQ This is due next class.
        1. Take a screen shot of your certificate and then hand it in on courseworks under assignments.
      2. The second course is the 20 hour coding course with id WPCSGD https://studio.code.org/join/WPCSGD You do not have to do the unplugged sections. This is due 2/5/24.  You CANNOT join both classes at once.
      3. Joining these classes is quirky.  Use the links above.  You can also first sign in to code.org then go to https://studio.code.org/join then type in the two codes above.  Check with me and I will make sure I can see your progress.
    2. Watch Video for next class and take the Quiz.

 

Homework (DUE Monday January 22, 2024 ):

  1. The Frozen Hour of Code.
  2. Watch Next Video and Take Video Quiz!
  3. Make Sure you Install Anaconda
  4. Watch Growth Mindset on Home Page and take quiz.

Class 5 -For Loops

Class Overview

Today we will work on two things.

  1.  We are going to solve the equation of a line and plot it (pdf=equationofline).  You will work together in your breakout room to do it by hand.  Then each person will implement it themselves.  Here is my answer. (pdf=equationofline-answer)
  2. Then we are going to work on For loops (pdf=for-loops).  We will first just talk about looping in class and then work through a notebook.  Here is some reading on for loops.  http://www.tutorialspoint.com/python/python_for_loop.htm

VIDEO

Quiz is on courseworks for the video!

Homework 4 Due Monday February 5, 2024

QUESTION 1

Use 2 nested for loops.  This is a for loop inside a for loop.  Count up in the outer for loop from 0 to 9 and then at every step count back down to zero.  Remember that in np.arange(start,stop,skip).  You give it a start,stop, and skip.  We usually put numbers in.  But you don’t have to add numbers you could put a parameter in.

Answer Question 1.

i= 0
k= 0

 

i= 1
k= 1
k= 0

 

i= 2
k= 2
k= 1
k= 0

 

i= 3
k= 3
k= 2
k= 1
k= 0

 

i= 4
k= 4
k= 3
k= 2
k= 1
k= 0

 

i= 5
k= 5
k= 4
k= 3
k= 2
k= 1
k= 0

 

i= 6
k= 6
k= 5
k= 4
k= 3
k= 2
k= 1
k= 0

 

i= 7
k= 7
k= 6
k= 5
k= 4
k= 3
k= 2
k= 1
k= 0

 

i= 8
k= 8
k= 7
k= 6
k= 5
k= 4
k= 3
k= 2
k= 1
k= 0

 

i= 9
k= 9
k= 8
k= 7
k= 6
k= 5
k= 4
k= 3
k= 2
k= 1
k= 0

 

QUESTION 2.

Go back and get the monthly precipitation from central park that you used in class.  Remember that we used this data when we were learning about lists and learning how to make plots (here is the link list today and plot it).   Use a for loop and sum up the monthly data.  Then call the function sum on your data.  It will be np.sum(precip_list).  How do they compare?

Answer Question 2.

For loop sum= 45.13

sum function sum= 45.13

QUESTION 3.

Create two lists.  One with the day of the week and one with the number of classes you have on that day. Use a for loop to go through your lists and printout how many classes you have each day.  Then write your total number of classes.

On Sunday I have 0 Classes
On Monday I have 2 Classes
On Tuesday I have 0 Classes
On Wednesday I have 2 Classes
On Thursday I have 0 Classes
On Friday I have 0 Classes
On Saturday I have 0 Classes

In total I have 4 Classes
QUESTION 4.

Using np.arange or np.linspace and a for loop to recreate what is below.  Remember that np.sin takes radians and not degrees. You can convert yourself or use the function np.deg2rad().  Also, I wrote out degrees and did not use the symbol because latex does not show up in print statements but it does on graphs.  Don’t forget what you learned about format statements a few classes ago to get all the decimals correct.

The sine of 0 degrees is 0.00
The sine of 10 degrees is 0.17
The sine of 20 degrees is 0.34
The sine of 30 degrees is 0.50
The sine of 40 degrees is 0.64
The sine of 50 degrees is 0.77
The sine of 60 degrees is 0.87
The sine of 70 degrees is 0.94
The sine of 80 degrees is 0.98
The sine of 90 degrees is 1.00
The sine of 100 degrees is 0.98
The sine of 110 degrees is 0.94
The sine of 120 degrees is 0.87
The sine of 130 degrees is 0.77
The sine of 140 degrees is 0.64
The sine of 150 degrees is 0.50
The sine of 160 degrees is 0.34
The sine of 170 degrees is 0.17
The sine of 180 degrees is 0.00

 

Final 10%

Fun with two for loops, line breaks, new lines, and np.arange.  Can you make the pattern below?  Remember you can do math in np.arange.

0
0 

1
1 2 3 4 5 6 7 8 9 10 

2
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 

3
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 

4
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 

5
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 

6
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 

7
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 

8
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80

Class 04 -More lists, Start Strings

First we are going to explore a little bit deeper into range and lists (pdf=range-linspace) and make some fun plots.

Second, we are going to look at strings  (pdf=strings)in more detail.   You can read more about strings here http://www.tutorialspoint.com/python/python_strings.htm  and this website goes into more detail on the formatting we did.  https://mkaz.com/2012/10/10/python-string-format/

VIDEO

Make sure to take your Quiz on Courseworks!

HOMEWORK

Homework 3 Due Next Class (Wednesday September 21, 2022)

  1. Code.org intro course through stage 15 to stay on pace
  2. Write 50-100 letters of nonsense in a string.  But in that nonsense have a secret code that spells your name with every x letter (e.g. every 5th letter).
    1. print the whole string
    2. use slicing to print your name
    3. use slicing to print your name and then make it upper case
  3. Repeat the same thing with a list but only do your first name. This is different as you are using a list.  #2 above uses a string and this uses a list.  It is a subtle difference but make sure to do it correct for each.
    1. Write the list.
    2. Use slicing to write your name
    3. Write your name in reverse using slicing (for this to easily work the last letter of the list needs to be the last letter of your name)
    4. reverse the list
    5. write your name backwards using slicing on the reversed list.
    6. with the list reversed write your name forward with slicing.
  4. Final 10% today.  Practice some more plotting and make the graph at the bottom of the page. You should be able to put together your line plotting and cosine plotting to make it.  The graph below shows cosine.   I am okay with an ugly B.  You will need to create two and only two numpy arrays to make the B if you set all the different coordinates correctly.  But there are many ways to make a B. But as a hint think about how you can define points in the B.
  5. string-and-list-hw grading rubric

My Answers

My secret coded string!
Boerrianion4an6nn09  i  Jkaj.hif ksfMifnasgmi30flbn-lniao238uasdx
My name in the string using slicing!
Brian J. Mailloux
My name in the string all in upper case
BRIAN J. MAILLOUX
The list
[‘B’, ‘o’, ‘e’, ‘r’, ‘r’, ‘i’, ‘a’, ‘n’, ‘i’, ‘o’, ‘n’, ‘4’, ‘a’, ‘n’, ‘6’, ‘n’, ‘n’]
my name using slicing
[‘B’, ‘r’, ‘i’, ‘a’, ‘n’]
my name backwards using slicing
[‘n’, ‘a’, ‘i’, ‘r’, ‘B’]
I reversed the list
[‘n’, ‘n’, ‘6’, ‘n’, ‘a’, ‘4’, ‘n’, ‘o’, ‘i’, ‘n’, ‘a’, ‘i’, ‘r’, ‘r’, ‘e’, ‘o’, ‘B’]
my name backwards using slicing
[‘n’, ‘a’, ‘i’, ‘r’, ‘B’]
my name using slicing
[‘B’, ‘r’, ‘i’, ‘a’, ‘n’]

Class 3 – Make a list and plot it

Today we are going to
1.  learn more about lists and then plot them (pdf=Lists Combined with Plotting)

Here is a reading on lists.  http://www.tutorialspoint.com/python/python_lists.htm

VIDEO

QUIZ After Video-Take the quiz on courseworks.

HOMEWORK

Homework 2 Due beginning of next class (Monday January 29, 2024).

  1. Code.org intro course through stage 15
  2. Make plots Like below.
  3. Hand in your notebook.  It ends in .ipynb.  this lets me run your notebook if there are any issues.

Make 2 lists

x=np.array([1,2,3,4,5,6])
y=np.array([6,5,4,3,2,1])

plot x versus y.

You will need to add this to the top of your code

 

%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt

The matplotlib inline tells the ipython notebook to show the graphs.  The import import matplotlib.pyplot as plt tells python to import the plotting package so we can use the plotting functions and make great plots.

Make an x,y plot using ax.plot.

Using the links in today’s notebook for ideas.

  1. choose your favorite shape
  2. choose your favorite color
  3. choose your favorite linestyle.
  4. choose something else to change (e.g. linewidth…)

here is my example-

What are the axes missing?

Add axis labels and a title?

Make sure to use Markdown to put your name and section at the beginning of the HW file and a description of the assignment

Use Markdown to add a figure caption.  This one can be brief but get in the habit.

 

This is my example but it is not perfect!!!!!  something similar without the missing parts will get you a 50.

x=np.array([1,2,3,4,5,6])
y=np.array([6,5,4,3,2,1])

fig,ax=plt.subplots()
ax.plot(x,y,marker=’^’,color=’r’,markersize=10,markeredgecolor=’g’,markeredgewidth=10,linestyle=’–‘)

hw2-picture
Final 10%:  To get the final 10% of the HW credit can you make a second plot with a slope of 4 and an intercept of 1?  Remember all the parts of the first graph.  Also, remember copy and paste are your friends……  Also remember what slope and intercept are!

Class 02 – Print, Markdown, directories, lists

Goals:

  1. We are going to learn some basic programming.
  2. Changing directories. (pdf=directory-structure – Jupyter Notebook) This is our first notebook for today.  We are doing two.
    1. Reminder.  If you want to download it from github right click on raw and choose save link as.  If you get a .txt file ending change it it .ipynb and you can now open it in your jupyter notebook.
  3. Markdown,
  4. basic math
  5. printing
  6. introduction to Python printing and lists (pdf=intro-to-python-types-print-lists)  This is our second notebook for today.

VIDEO FOR TODAY

QUIZ for after Video

  1. Remember that you need to take the quiz before class on courseworks!  It is labeled quiz 1 and called

    Quiz 1: Python Video on Directories and Printing

 

Notebook 1 Due beginning of Next class. (Monday January 22, 2024)

  1. Code.org intro course through stage 5 to stay on track.
  2. Look at the directory structure of your computer and make a place to work from when using Python (not graded, for your own organization)
  3. Use one print statement to make the Barnard B out of b’s with no spaces in the code but you can use backslashes in the print statements.  My example is below but you can make yours look nicer!  Your answer does not have to look exactly like mine.  But you need to use one print statement and that print statement can not have any spaces.
  4. Use print statements and .format to answer the math questions below exactly the same way with the exact formatting.  You need to set a and b and use them in your format statement.  Your print statement cannot have numbers.  Repeat-There are no numbers in your print/format statement.  You set the a and b before the print statement.
  5. Use Markdown in your homework to add your name and other critical information.  the homework should look nice with a nice Markdown header describing the homework.  This is critical.  You must add your name, date, section, and assignment in markdown.
  6. Upload your homework to courseworks.  You upload the notebook.  The file you upload should end in .ipynb
  7. Watch Next Video and Take Quiz

 

Barnard B (Really looks more like an 8)

Your answer should be similar to but hopefully nicer than

BBBBB
B        B
B        B
BBBBB
B        B
B        B
BBBBB

 

Use the print function and then \n or \t or something similar to move the cursor.  there should be NO SPACES in your print function!

 

Set
a=9.000
set b=4.000
Write the following sentence exactly.  using the .format nomenclature and no numbers only variables.  Use the a and b that you set in the format and print function.  Use the different operators with your variables.  Look at today’s handout for examples with the print and format functions.  The * should be in with the formatting calls.
When 9 is divided by 4.00 the answer is *2* with a remainder of 1.0
Then to check you did it correctly.  I will open your notebook.  I will change your a=9 to a=11 and it should give me this sentence
“When 11 is divided by 4.00 the answer is *2* with a remainder of 3.0”
During grading I also changed a to 15 and you should get a *3*