Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS190/295 Programming in Python for Life Sciences: Lecture 1

Similar presentations


Presentation on theme: "CS190/295 Programming in Python for Life Sciences: Lecture 1"— Presentation transcript:

1 CS190/295 Programming in Python for Life Sciences: Lecture 1
Instructor: Xiaohui Xie University of California, Irvine

2 Today’s Goals Course information
A basic introduction to computers and programs

3 Course Information Lecture: TT 3:30-4:50pm in ELH 110
Office hours: TT after class Course Prerequisites: none TA: Jake Biesinger Office: BH 4082 Grading based on Homework (5-8 assignments); no exams

4 Course Goals Introduction to computer programming using python
Primary targets of audience: Students in bio or med areas who are interested in learning a programming language Or students in other areas who are interested in using computers to solve life science problems

5 References Recommended textbook:
Python Programming: An Introduction to Computer Science, 2nd, John Zelle Lecture notes, references and assignments will be available from the course website (website link available from EEE)

6 Teaching format of the course
We will alternate between regular lectures and lab sessions. Regular lectures (basic programming techniques, concepts) Lab sessions, led by Jake Biesinger. Attendance is required. This is the way you will practice and improve your programming skills!

7 Topics to be covered Basic programming concepts:
Intro to computers and programs Write simple programs Computing with numbers Sequences: strings, lists and files Functions Loop structures Classes and object-oriented design Applications in life sciences Examples from biological and medical areas

8 Chapter 1: Computers and Programs

9 Hardware Basics CPU (central processing unit) - the “brain” of the machine, where all the basic operations are carried out, such as adding two numbers or do logical operations Main Memory – stores programs & data. CPU can ONLY directly access info stored in the main memory, called RAM (Random Access Memory). Main memory is fast, but volatile. Secondary Memory – provides more permanent storage Hard disk (magnetic) Optical discs Flash drives Input Devices – keyboard, mouse, etc Output Device – monitor, printer, etc

10 How does CPU execute a program?
The instructions that comprise the program are copied from the secondary memory to the main memory CPU start executing the program, following a process called the fetch execute cycle Retrieve the first instruction from memory Decode its presentation Perform the appropriate action Fetch, decode, and execute the next instruction

11 Programming Languages
A program is simply a sequence of instructions telling a computer what to do. Programming languages are special notations for expressing computations in an exact, and unambiguous way Every structure in a program language has a precise form (its syntax) and a precise meaning (its semantics) Python is one example of a programming language. Others include C++, Fortran, Java, Perl, Matlab, …

12 High-level vs. machine language
Python, C++, Fortran, Java, and Perl are high-level computer languages, designed to be used and understood by humans. However, CPU can only understand very low-level language known as machine language

13 High-level vs. machine language
Suppose we want the computer to add two numbers. The instructions that the CPU actually carries out might be something like this: Load the number from memory location 2001 into the CPU Load the number from memory location 2002 into the CPU Add the two numbers in the CPU Store the result into location 2003 With instructions and numbers represented in binary notations (as sequences of 0s and 1s) In a high-level language (eg. Python): c = a + b

14 Translate a high-level language to a machine language
Programs written in a high-level language need to be translated into the machine language the computer can execute Two ways to do this: a high-level language can be either compiled or interpreted

15 Compiling a high-level language
A compiler is a complex computer program that takes another program written in a high-level language and translates it into an equivalent program in the machine language of some computer

16 Interpreting a high-level language
An interpreter is a program that simulates a computer that understands a high-level language. Rather than translating the source program into a machine language equivalent, the interpreter analyzes and executes the source code instruction by instruction as necessary. To run a program, both the interpreter and the source are required each time. Interpreted languages tend to have more flexible programming environment as programs can be developed and run interactively, but are generally slower than compiled languages.

17 Python is an interpreted language
Start the Python interpreter in an interactive mode >>> is a Python prompt indicating that the interpreter is waiting for us to give a command. A complete command is called a statement

18 Defining a new function in the interactive mode
Python allows you put a sequence of statements together to create a brand-new command called a function. The first line tells Python that we are defining a new function called hello. The following lines are indented to show that they are part of the hello function. The blank line lets Python know that the definition is finished Notice that the definition did not cause anything to happen. A function is invoked by typing its name.

19 Defining a new function with parameters
Commands can have changeable parts called parameters that are placed within the parentheses Now we can called the newly defined function with parameters:

20 Write Python programs Type definitions into a separate file, called module or script. Save the file on a disk Several ways to run the program: python chaos.py >>> import chaos # in the interactive mode As Python imports the module file, each line executes. It’s just as if we had typed them one-by-one at the interactive Python prompt. Once imported, main() can be re-invoked by typing >>> import chaos.main()

21 Inside a Python program
comments: any text from # through the end of a line intended for humans, ignored by the Python defining a function called main x is variable, used to give a name to a value so that we can refer to later The statement starting with for is an example of a loop A loop is a device that tells Python to do the same thing over and over again The lines indented underneath the loop heading form the body of the loop x = 3.9 * x * (1-x) is an assignment statement: the value on the right-hand side is computed, and is then stored back (assigned) into the variable on the left-and side of =.


Download ppt "CS190/295 Programming in Python for Life Sciences: Lecture 1"

Similar presentations


Ads by Google