0% found this document useful (0 votes)
34 views

Programming For Scientist Lecture 1

Uploaded by

alyssayuan2002
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Programming For Scientist Lecture 1

Uploaded by

alyssayuan2002
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

Programming for Scientists

COMP1730 & COMP6730


Introductions
Co-convenors
https://comp.anu.edu.au/courses/comp1730/people/
Semester 1, 2024:

Dan Andrews

Brian Parker
Course structure
• Week 1 – Programming Basics, Variables and Expressions
• Week 2 – Functions and abstraction
• Week 3 – Code branching and Iteration, Strings
• Week 4 – Lists (Canberra Day holiday on the Monday) Dan
• Week 5 – References, Dictionaries, Code best practices
• Week 6 – Modules, Classes, File IO
Teaching break
• Week 7 – Introduction to scientific libraries with NumPy, Debugging
• Week 8 – Data analysis with Pandas, Visualisation, Dictionaries, Sets
• Week 9 – Advanced functions, Errors and exceptions
• Week 10 – Computational complexity, Dynamic programming
Brian
• Week 11 – Computational methods in science and engineering
• Week 12 – Computational methods (cont), Exam revision
See: https://comp.anu.edu.au/courses/comp1730/lectures/
Lecture slides and code examples:
• Course website:
https://comp.anu.edu.au/courses/comp1730/lectures/
About you – results of demographic survey
About you – results of demographic survey
About you – results of demographic survey

Typical student: science or computing, use Windows


computer, can code a little

Diverse though? some law students that code well


already and use linux, maybe?
Introductory Lecture - format

• Orientation to python – let’s look at some code first


• Learning to program
• Reference books and other reading
• Variables and Expressions (part I)
AND (at the end):
• Admin:
• Lab class enrolments
• Assessment
• Other announcements
Hello, World!
• Brian Kernighan, of C fame, is attributed to be responsible for the first
‘Hello, world!’ program.
• It is much simpler to implement this in Python than C for the early
1970’s
In C:

Source: Wikipedia

In Python (in the interpreter interactive mode):

Brian Kernighan, ca. 1972


Example: Running python programs?

• Code_L1_1.py

• Interactive mode python


• Script mode – files that end with *.py
• Running in a terminal
• Running in an Integrated Development Environment
What does this look like in Python?
Start

YES Does it NO
move?

YES Should Should NO


All good! it it All good!
move? move?
NO YES

Stop
In Python:
Code_L1_2.py
More complicated: Python as a toolbox
Code_L1_3.py
What is programming?
COMP1730 & COMP6730

Reading:
Chapter 1: Downey, Think Python,
Chapter 1: Sundnes, ItSPwP
OR
Sections 1& 2: https://docs.python.org/3/tutorial/index.html
Why Python?

• This is not a course on programming in


python. It is a course on programming that
uses python
• Why python?
• Python is a very popular programming language
• Especially in science and engineering
• Open source, available on most platforms
• Huge external code libraries for doing just about
everything, in:
• Data Science
• Machine Learning
• Bioinformatics…
• We will use python 3 (beware older books
that are python 2)
Python creator, Guido van Rossum in 2019
This course

• Is a first course in programming, in python


• Focused in transferable, practical skills
• Coding languages come and they go – but the good coding practice is relevant
to all languages
• Useful to those in science and engineering.
• Not foremost teaching commercial software engineering
• A beginners course – no prior experience required. But this doesn’t
mean we are going to go slowly, or that it will be easy!
• We will use python 3
Coding as a craft
• Some recommendations:
• Read widely and write code frequently. Practice, practice, practice.
• This won’t end well if it is already week 9 and this is the first time you are
looking at the course.
• Textbooks and reading: if you only attend one part of this course, make
sure it is the tutorials. Though, these will be very hard if you don’t at
least attend lectures or do the course reading
• In the beginning, as you start to write your first programs, it might feel
bad as you make all the beginners mistakes. Don’t worry and keep
trying. Everyone starts here.
• Error messages are your friend…
Reading: Course Textbooks

Alex Downey (2016) Think Python, 2nd Edition


Sundnes (2020) Introduction to Scientific Programming with Python (ItSPwP)
(electronic copies available at: https://comp.anu.edu.au/courses/comp1730/resources/)
• Other good resources:
https://docs.python.org/3/tutorial/index.html
• Other books:
Al Sweigart (2015) Automate the Boring Stuff with Python
Bill Lubanovic (2019) Introducing Python, 2nd Edition

• When reading other python books, make sure they are python 3!
• Be careful with web resources – some are great (eg. docs.python.org). Many
aren’t.
Safari Books (ANU library subscription)
https://www.oreilly.com/library-access/

Or, as a PDF file: https://greenteapress.com/wp/think-python-2e/


Variables (part I)
COMP1730 & COMP6730

Reading:
Chapter 2 : Downey, Think Python
Chapter 2, Sundnes, ItSPwP
OR
https://docs.python.org/3/tutorial/index.html
Variables – what are they?
• Contain a program’s data whilst it is executing
• Assignment statements:

Downey (2015) Think Python, 2nd Ed.

• In memory – the ‘state’ of the program:

Code_L1_4.py
Types of variables (in python)
• All variables have a type – and you
will get an error is you store an
incompatible value in the wrong type
(eg. a string value in an integer
variable type)
• Or try to do something inappropriate
with a data type (eg, print an integer
as a string)
• Basic data types:
• int – integer
• float – decimal values
• str – strings of one or more characters Sweigart (2019) Automate the Boring Stuff with Python, 2nd Ed.

• bool – Boolean values, True or False


• And variables that contain multiple
values of basic data types:
• List and Tuple – sequences an index
• Dict – a hash, key-value pairs
Every variable has a type

• Variable types in python: • The type() function tells us the


• Integers (type int) type of a variable:
• Floating-point numbers (type float)
• Text strings (type str)
• Truth or Boolean values (type bool)

• Variable types determine what we


can do with values (and sometimes
what the result is)

Code_L1_5.py
Numeric types: int
• int types represent the mathematical integers (positive and negative
whole numbers) (0, 1, 2, -1, -17, 4096,…)
• Values of type int have no inherent size limit in python

• Note: can’t use commas to format integers for readability


• Write 128736 not 1,282,736
Numeric types: float

• Floating-point numbers (type float) approximate the mathematical


real numbers
• Values of type float have limited range and limited precision
• Min/max ± 1.79 x 10308
• With a few exceptions to this limit
• Though this is the typical limit – the actual limits depend on the python
implementation
• Type float also has special values ± inf (infinity) and nan (not a
number)
String variables

• Strings (type str) represent text


• A string literal is enclosed in single or double quote marks

• A string (in python) can contain other types of quote mark, but not
the one used to delimit it
• More about strings (so much more) in a coming lecture
Suggested Exercises

• Complete Exercises 2-1 and 2-2 on Page 18 & 19 of Think Python.


Course Organisation
COMP1730 & COMP6730
Course Admin, Information and Contacts

• https://comp.anu.edu.au/courses/comp1730/
• Wattle for announcements, forums, quizzes, surveys and assignment
submission
• Recordings of lectures are available on Wattle
• Read the Wattle news and announcements!
• To ask a question:
• Use the discussion forum on Wattle
• Ask your tutor in labs
• For private matters, use the course email: [email protected]
• Always use your ANU email address, to avoid the spam filters
• Please don’t email the course convenors directly – these emails will be ignored
Schedule overview
• Two lectures per week
• All lectures will be presented live and will be recorded
• Follow content and schedule:
https://comp.anu.edu.au/courses/comp1730/lectures/
• One 2-hour lab per week, starting from Week 2
• Before Fri 23rd Feb - Sign-up for a lab class with MyTimetable (linked via Wattle):
https://mytimetable.anu.edu.au/odd/student
• Assessments will be due at 11:55pm on Sunday of weeks when due (unless
otherwise specified):
https://comp.anu.edu.au/courses/comp1730/assessments/
• You are expected to spend another 6 hours per week studying the course:
• doing the recommended reading
• solving all lab exercises, and
• time spent to practice coding
Drop-In Sessions

• As of this semester, we are continuing weekly drop-in sessions for 1-


to-1 tutor contact
• Times will be announced in later in 1st Term
• Python installation help sessions:
• Tues – 3-5pm – Birch Building, Lab 1.08
• Weds – 4-6pm – Hanna Neumann Bldg, Computer Lab 1.24
• Thurs – 11am-1pm – room N114, CSIT Building (#108)
Assessment (preliminary)
• Assignment:
• Individual assignment is a take-
home programming assignment
• There will be a viva component of
the assignment assessment
• Held during weeks 11 and 12 at same
times as your usual lab session
• Students are expected to have a
thorough knowledge of their own
See: https://comp.anu.edu.au/courses/comp1730/assessments/ work and be able to speak in detail
about their answers and solutions
• Final exam:
• In-person, in computing labs
• COMP1730 & COMP6730 at different • The assessment scheme will be final
times at end of Week 2. Any changes will
• Not a hurdle assessment be announced.
Academic honesty
• Submitted code will be checked computationally for evidence of plagiarism.

• If evidence of plagiarism is found in individual homework problems, the mark for that individual homework will not be
posted, until all homeworks have been assessed. In the context of all homeworks if it is decided there is evidence of
repeated plagiarism, students will be interviewed for possible action of academic misconduct.

• The take-home assignment and exam will also be checked for evidence of academic misconduct.

• What is okay: for the homework, discussing the programming problems and approaches to solve them with other
students is allowed, provided that no code is exchanged and that the final solution and code is written individually. In
this case, the other students involved in the discussion must be listed in a comment at the top of the homework.
• For the final exam and take-home assignment must be individual work. You may not discuss the questions or your
answers with anyone (this includes any on-line forum).

• Note that in all cases every line of code submitted must be fully written by you from scratch (and not just a modified
copy of a version from the internet), and must be fully understood and explainable by you. Sufficient inline comments
should be provided to make clear that you understand the code.

• Note on large language models and other code generators: generative AI models such as github copilot, chatGPT, Bing
chatbot etc can be used by students for the homeworks and take-home assignment to explore solutions and
understand their own code. They will not be allowed for the final exam. But in all cases the final code submitted by the
student must be fully written and understood by the student, as described above.
• If you are unsure, please ask your tutor or the convenors.
Assessment

• All assignment deadlines are hard – no late submissions will be


accepted. Unless previous permission has been granted.
• Extension requests and late submissions require documentary
evidence, such as a medical certificate
• Regarding deferred assessments and special consideration, please
read: https://www.anu.edu.au/students/program-
administration/assessments-exams
• Please note that “any submitted work may be subject to an additional
oral examination”, which can change the assessment mark in any way.
Useful Links:

• Install python - if you want to start, follow the instructions to install


python (via Anaconda) on your laptop:
https://comp.anu.edu.au/courses/comp1730/labs/install/

• Lab materials - this is where to find the labs:


https://comp.anu.edu.au/courses/comp1730/labs/

• And the assessment description:


https://comp.anu.edu.au/courses/comp1730/assessments/
Wattle Discussion forum
In general, this is where you should go to ask questions

3 simple rules:
1. Read before you post.
• Before posting a question, check if your question has already been answered

2. Give you post a good, descriptive topic


• Don’t write ‘A question’. Write something like ‘Variable assignment: why does the value not
change?’

3. You may not post solutions to assignment problems

These rules are good etiquette and apply to any online forum.
Important tasks:

1. Complete the demographic information 4. Prepare for the labs! Attend lectures, read
questionnaire on course Wattle page lab instructions – and attempt some of the
2. Sign up to a lab class! exercises before attending your lab
• Do this via myTimetable: 5. Make sure you have a working python
https://mytimetable.anu.edu.au/odd/student programming environment:
• Link also accessible from Wattle page • Install Anaconda on your own computer:
• Do this by end of Week 1 (Fri 23rd Feb) • Go to: https://www.anaconda.com/download
• Labs start in Week 2 • Current installation will give you python 3.9 or later
• Homework 1 is also due in Week 2 • Includes that Spyder IDE as part of installation
• In-lab assessment starts in Week 2 • For more tips and detailed instructions:
https://comp.anu.edu.au/courses/comp1730/labs/install/
3. Login to STREAMS: https://cs.anu.edu.au/streams/ • Or, install another python3 implementation
• This will create an account for you on the lab • Or, verify that you can reliably use the lab
computers computers

You might also like