What You Should Know For Lecture: Week 4

Wednesday:

Announcements-

Homework

Any exercises not completed in class will be due Monday. In class exercises from Monday will be due today at 11 pm. There is also an HW 4 assignment due today by 11 pm.

Python Tutorials

Here are a few python tutorial / resources: https://wiki.python.org/moin/BeginnersGuide/NonProgrammers https://blog.kowalczyk.info/articles/pqr26/pqr26int.html https://automatetheboringstuff.com/ http://openbookproject.net/thinkcs/python/english3e/ http://www.mustitz.net/attachments/download/334/Python_Programming_for_Biology_Tim_J_Stevens.pdf http://www.pythonlearn.com/html-270/ https://datacarpentry.org/semester-biology/materials/python-resources/

Project

If you are worried about your project, come to my office hours. They are after class at the Music Cafe.


Python!

What is python? “Python is powerful… and fast; plays well with others; runs everywhere; is friendly & easy to learn; is Open.”


How to load python on Hoffman2?

Much like we load git in order to run git on Hoffman2 we also have to load python. There are a lot of versions of python on Hoffman2, for now let’s use the default version.

$ module load python

You can check the version by typing the following:

$ python --version
Python 2.6.6

Now to launch python type the following:

$ python
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

The >>> indicates the command prompt.

If you want to quit python type

$ python
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
$

Doing math in python

­Addition: a + b
Subtraction: a - b

Multiplication: a * b

­Integer Division: a / b

  • Note that when division is performed with two integers, only the quotient is returned (the remainder is ignored.)

­Power: a ** b.

Equals: a == b

Differs: a != b

Greater: a > b

Greater or equal: a >= b

Less than: a < b

Less than or equal: a <= b


In class exercises

Please add your responses to a text file called _week4_inclass.txt. When you finish, please copy the text file to /u/home/class/c177/c177-i0/classdata/In_class/Week4/Wednesday

1. List three websites where you can find help scripting in python.

2. What is the command to load python on Hoffman2? What command runs python on Hoffman2? How do you exit python?

3. Write a command to print your first middle and last name on different lines. For example:

Emily

Elizabeth

Curd

4. Bash and python handle variable storage differently. What is the difference? hint: I am specifically looking for answers related to white spaces.

5. What is the difference between int and float variables. If you do not indicate float variables what is not returned during division?

6. What is the output of:

print 3 * (1 + 3)

print ‘23’ + ‘8’

print 23 + 8

print ‘23’ + 8

print 8 < 7

print 8 == 7

print 8 <= 7

print 8 >= 7

print 8 > 7

7. What commands would give you the following outputs:

pickled cabbage 88

‘pickled cabbage 88’

8. How does concatenating variables in python differ from in bash? For example, how would you get the variables storing ‘sun’ and ‘shine’ to print ‘sunshine’ in bash vs python?

9. What does the blue text in a markdown document indicate?