You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »


Math and intro to random numbers

Find a partner - or I will do it for you.  I mean it!! THIS IS IMPORTANT.  If you don't do it, your score will be penalized.  If you don't like to work with a partner, then it is even more important for you to do it. 


NOTE:  I expect Rivanna will be down during our class.  If so, we will use Google Collaboratory instead.  It is an environment very similar to Jupyter Notebook.  Instead of using the repository (as in the normal directions below) please load the notebook (and make a copy in your Google drive account with the directions below):  https://colab.research.google.com/drive/1KanesIrH-zKh316K7siFPCv0UrzWbbax?usp=sharing

You will need to save a copy in your Google Drive by clicking the "File" drop-down menu at the top left of the screen and selecting “save a copy in drive".  You should be able to run AND edit the new copy in your Google Drive area.  

Note - if we have to use Google Collaboratory, JUST FOR TODAY you can upload your file to your GitHub repository by downloading it to your computer, and then using the GitHub interface to upload the file.  


You may need to refer to this week's reading assignment throughout the exercises. 


Announcements

  • You are off to a great start!  Keep it up! 


Goals

  • Learn how to import modules (and figure out how to use them)
  • Introduce Random numbers and the random number seed
  • Use the Python math module (review - time permitting)

0) Get the GitHub repository for class06 and clone it to your area in Rivanna. 

Note: Ignore (0) if using Google Drive.  


Use this link to accept the assignment and create your repository for class06 on GitHub:  https://classroom.github.com/a/V-2UFgle

After you accept the assignment and the repository and it exists in your GitHub, as we did in class02, clone the class06 repository into your working area on Rivanna. 


>>>  git clone git@github.com:PHYS1655S24/class06-<userid>.git

 Navigate into that directory via usage of the 'cd' command.




1) Play with random numbers


1a) Work through the Random.ipynb JupyterLab Notebook.  It is in your repository.   Complete the exercises within. 


→  Add, commit, and push your Random.ipynb to GitHub and make sure it is there.  

(or, if we had to use Google Drive, download to your computer and the upload using the GitHub interface.  



1b) Based on what you learned in the Notebook. Write a python program (a script) called random10.py that prints 10 random x,y (two each time through the loop for a total of 20 random numbers) float values to the screen where each value is between -1 and +1. 

Note:  You can't do 1b on Google Drive..


NOTE: start by copying triangle.py to random10.py:


>>> cp triangle.py random10.py

→ Design you algorithm and implement the code in random10.py.

→  Add, commit, and push your random10.py to GitHub and make sure it is there.  




NOTE:  part 1b is useful in HW04, so make sure you get it done.


2)More with the math module



Open Google and type "Python math module examples".  Look at a few.  You can do this with any module that you want to use to understand simple things that can be done.  When we know a little more python, we can better understand the python module documentation - for now looking at examples will do.  A major part of learning to program is learning how to read the documentation.  We will continue to work on that this semester...


If Rivanna is down: use this notebook on Google Drive:  https://colab.research.google.com/drive/19zyYHbqso_1Rg1HULbZy_W-SjOCzd_RG?usp=sharing


Now, modify the program:  Calculate and print to the screen the length of the long side of the triangle.  Calculate and print the values of the two remaining angles.  You will need to use the trig functions that come with the math module.   Your program should add the angles and make sure they equal 90 degrees, and print to the screen that it either did, or did not, pass the check. 



Remember what else is available to you in the math module?  Have a look at the documentation.


→  Comment, add, commit, and push your triangle.py to GitHub and make sure it is there.   (or, if we had to use Google Drive, download to your computer and the upload using the GitHub interface).  


Done?  Did you document your code?  If not, add some documentation to your programs, and re-post them to GitHub:    triangle.ipynb,  and Random.ipynb. 




  • No labels