Important:  I expect you to work in pairs for all in-class exercises.  Your partner is the first one to talk to with questions - then if you and your partner have a question together - the TA's or PG will be happy to work with you to solve it.  You may also communicate with students outside of your group.   We are working together to learn how to use these tools as efficiently as possible... 

Class exercise work is due on Collab by 12:30pm of the following day.  In-class exercises will be graded only based on participation. 


Work with a partner! 

Goals

  • Learn the anatomy of  python program and how to run it.
  • Get acquainted  with the JupyterLab environment, and learn how to use a Jupyter notebook. 

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

Login to Rivanna

Use this link to accept the assignment and create your repository on GitHub: https://classroom.github.com/a/LVryP3qZ

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


>>>  git clone git@github.com:PHYS1655Su24/class03-<userid>.git


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


1. Reading the on-line manuals

From the Linux command line on Rivanna, try the man command to see several manual pages. For example: man ls, or man mkdir, or man man.  Remember you can do this with any Linux command for a reminder of syntax and what it can do. 

2. A simple program

In your new repository, you will see the same hello.py file that we used in class02.  It looks something like this: 


#----------------------------------------------------------------------------
# PROGRAM NAME: hello.py
# PURPOSE: Simple python example
# CREATED: Craig Group 2023
#
# Class01
# UVA Honor Pledge
#
# To run me: python hello.py
#____________________________________________________________________________

#------------------------------------------------
# IMPORTS
#------------------------------------------------
#None


#------------------------------------------------
# GLOBAL CONSTANTS
#------------------------------------------------
#None


#------------------------------------------------
# METHODS
#------------------------------------------------
#None

#------------------------------------------------
# MAIN FUNCTION
#------------------------------------------------
def main():

    #To print something to the screen in Python.
    print("\n Hello Python Universe!\n\n")


#Call the main function
main()




This is your first Python program! To run the program:

python hello.py

If you get error messages, check that you typed the program name correctly and that you are in the same directory as hello.py. 


Anytime that you write a new program you should start with an existing one, or a 'template' program.  For now, you can use 'hello.py'.  In fact, I use something very similar to hello.py for every new program I write. The benefit of this is that you know you are starting with a file containing your program that has the main pieces you need and, most importantly, with no syntax errors.  You can use the 'cp' command to make a copy with a new name and then edit that file.

>>> cp hello.py new_program.py

Then, you can do your work in new_program.py.

hello.py doesn't do much (just one print statement in the main function and some comments), but it has placeholders for things (titles in comment statements) that we will learn how to do later. We can create our own user-defined functions in the 'METHODS' section, define 'GLOBAL' constants that will be available from anywhere in our program, and 'IMPORT' Python modules that contain functionality that we might want to use in our programs. 


3. A short Jupyter Notebook


Open JupyterLab - remember, this is just like starting an OnDemand desktop session, but instead, you select JupyterLab from the drop-down menu.  NOTE - make sure to select 'HOME' under the work directory option, and to put 'phys_python' for the allocation option.  

You need to be a little patient - it will take <1 minute to get a node for you, and then <1 minute to connect to that node.  For future classes, you might want to go ahead and connect to JupyterLab at the beginning of class so you are ready when we start the in-class work. 

You can use the file navigator on the left side of the screen to find your class03 directory, and open (double click on) 'hello.ipynb'.  Work through the jupyter notebook and complete the exercises inside.   This should help you understand exactly what 'hello.py' is doing and introduce you to several python topics. 


4. Practice submitting your work

Practice submitting your work. You should submit your work as soon as it is complete, but you must submit the files created today before 12:30 on the day after class.  The in-class work is meant to keep class time productive.  It is designed to keep most students learning for the whole period.  You may not have time to finish, and you are not required to finish what you can't do during class time.  Don't feel obligated to spend much extra time on it outside of class.  However, you might need to finish parts of it before you can successfully do your homework.  The homework often builds on the in-class work. 

Make sure to post what you completed so that you get credit for your participation!

Type: git add *, git commit -m 'comment', git push  

Then, check the GitHub webpage to make sure it worked.

5. Make your first entry on the course Piazza page

Piazza is a great place to get answers to questions from the professor, TA's, or other students.


Make a post to introduce yourself (you can find the link on the course Wiki home page). In the 'other' tab, you should see an entry “Introduction Thread”. Click on that and then you should be able to type a comment in the “Start a new follow-up discussion” box.  What are you excited about or worried about with this class?


Note: it is also possible to make private posts that only the professor and TAs will see. Use this for posts later in the semester if you are not sure if it is appropriate to share with the whole class.  For example, if it includes code that might give away how to do the homework... 

Also note:  please feel free to help answer questions from other students throughout the semester.  Everyone will learn more if we ask, and answer questions on Rivanna. 

Summary

This introductory exercise provided us with some foundational knowledge that will be essential going forward in this class. If you struggled with any of these concepts, I recommend returning to it and doing them again on your own or coming to office hours.


Done?  Make sure your work is cleaned up and push files to GitHub.

  • No labels