Download as pdf or txt
Download as pdf or txt
You are on page 1of 62

ECS32A

Introduction to Programming
Fall Quarter 2022

Unit 1

Introduction
Dr. Kristian Stevens
“Computer science is the new math”

–Christos Papadimitriou
Welcome to ECS32A!
• Our goal this quarter is to learn how to write programs.

• This course is for people with no programming experience. You


will learn a computer programming language by writing useful
programs both small and large.

• It’s not just computer science majors who program, the


students who take this course are much more diverse! We will
focus on the pleasure and utility of programming.

• You will nd that learning to program is like learning to speak


in a new language. If this is your rst time, you will bene t from
many opportunities to practice and people to practice with.
fi
fi
fi
ECS32A Aggies
by Major
What do these majors have in common?
DATA
Freshmen Sophomore Junior Seniors
Poll Results
Spring Quarter 2022
Why learn to program?
• While programming is something computer scientists do,
computers are used in almost every major.

• We focus on programming is a tool for exploring data and solving


problems. Programming is a tool that goes "beyond the
capabilities of a spreadsheet".

• You will nd many times that the programs you can buy are not
exactly what you need, or data you have is not in the format you
want. Programming is a solution to this.

• Even if this is your last Computer Science course; I want you to


leave this class with a powerful, exible, and free tool; and
appreciate how you might use it in your eld.
fi
fl
fi
How does programming help?
• After this course you will have a better idea of what can be
done with programming. Most programming languages will
express the same concepts you’ll learn here with different
syntax.

• Learning to write programs will develop your problem solving


skills.

• With this skill will be able to handle much larger and more
complex problems yourself.

• Programming is an analytical and quantitative skill you can


put on your resume, regardless if you are applying speci cally
for a programming job.

fi
Python!

Let’s learn more about our


programming language and why?
Why Python?
Python Popularity in Github

https://octoverse.github.com
Why is Python so Popular?
Portability

• Python programs run unchanged on most major computer platforms

• Python is accessible, free, and comes with IDLE

Software quality

• Python code is simpler and more readable

• Python is object oriented

Developer productivity

• Programs are shorter and are run immediately by the interpreter

• Lots of libraries that do things like graphics, sound editing,


computational biology, web development, statistics, nance,
databases, arti cial intelligence and machine learning, etc…..
fi
fi
IDLE: Integrated Development
and Learning Environment

The IDLE shell is a unique feature of Python that allows


you to execute Python expressions and statements
in real time. You will install IDLE this week.
Python Readability and Code Quality

• As Guido van Rossum said:

"Code is more often read than written"

• He designed the Python language with


readability in mind.

• Python programs generally have a shorter and


simpler syntax than the equivalent programs in
other languages.

• This makes Python code easier to understand.


Python really is simpler
Python print("Welcome to ECS32A!")

#include<iostream>
using namespace std;
int main()
C++ {
cout<<"Welcome to ECS32A!";
return 0;
}
public class Main{
public static void main(String[] args)
Java {
System.out.println("Welcome to ECS32A!");
}
}
Python programs are typically 3-5 times shorter than equivalent Java
programs and 5-10 times shorter than equivalent C++ programs.
Rapid Development
There are a number of features that make Python
programs quicker to write and easier to debug:

• Python programs are shorter and easier to read

• Python is interpreted and not compiled

• Python promotes code-reuse with features such


as functions, modules, and object oriented
programming

• Python has many built in and third party modules


Python Modules
Much of the utility of Python is access to modules
of code within the Python distribution and beyond.
Matplotlib is a data visualization module we will use.
Python is widely used in industry:
Google, YouTube, Dropbox, Instagram,
Tesla, NASA, NSA, ILM and Pixar.
Here is an editorial from python.org - ILM are big fans.
Examples of what you
will learn

ECS32A
Example of What You’ll Learn
Example of What You’ll Learn
Average July temperature anomaly in
Sacramento from 1880 to Present

Noisy!
Example of What You’ll Learn
Same data after moving average to
decrease noise.

Now we see the trend


Visualizing the World
Happiness Survey
Example of What You’ll Learn

1935
Social Security Act Signed

1937
600,000 cards
were
processed
each day
Social Security Card
Application Database

Over
450,000,000
cards issued
as of 2018

We can calculate
the popularity of
any baby name
from 1880 to now
Book Art

Visualize
the important
words in a text
at a glance.
Course Overview
& Getting Started

ECS32A
Course Outline
Week Topic Chapters

1 Introduction 1 Overview

First programs variables, types,


1-2 2
statements, input and output
Basic
2-3 Conditional execution 3 building blocks
of programs
4 Functions and Iteration 4,5

5-6 Working with Strings and Files 6, 7 Data processing

7-8 Lists, Dictionaries, and Tuples 8, 9 Data structures

9-10 Object oriented programming 14


Bridge to 32B
and other "big ideas" in CS and beyond.
Our Textbook
• PYTHON FOR EVERYBODY
Exploring Data in Python 3

• We are using the LibreTexts edition of


the textbook.

• The book is "designed to introduce


students to programming and software
development through the lens of
exploring data"

• We will cover Chapters 1-10 and 14


The Textbook is Interactive!
Course Structure
• Programming Assignments – 50% of grade.

• Breakdown:

• Gradescope homework scores – 45%

• Coding style and best practices – 5%

• You may work in groups of up to three, but you must


write your own programs and use your own words
(not your partners) to describe your program in the
comments or risk no credit on the assignment.
Programming Assignments
• Learning any new language requires at lot of practice and that is
where the homework assignments come in.

• You may work in groups of up to 3, but write and submit your


own assignments. Comments must be in your own words.

• You may submit an assignment as many times as you like before


the deadline until you get the score you want.

• You will get 50% credit on any additional points submitted after
the deadline. This is added at the end of the quarter.

• We will manually grade your comments from HW2 onward to


make sure you wrote and understood your submission. This is
calculated at the end of the quarter as your coding style grade.
Exams and Quizzes

• Exams and Quizzes - 50% of grade

• Breakdown:

• Best 2 Exams – 36% of your grade.

• Best 6 Quizzes - 14% of your grade.


Makeup Policy
• In lieu of offering makeup exams, we will be
dropping your lowest exam score.

• Your lowest homework assignment will be


dropped and an additional comprehensive
makeup assignment will be offered towards the
end of the quarter for further improvement.

• Your lowest quiz score will be dropped and an


additional makeup quiz will be offered towards
the end of the quarter.
Weekly activities
• Lecture – 3 hours
Includes coding examples and demonstrations
There will be opportunities to type along and ask
questions.

• Discussion sections – 1 hour

• Piazza & Discord - TAs will be online on Piazza 7


days a week! Tutors will be using Discord.

• Of ce hours and SLAC – The place to go for help


with programming. These are in-person and on
Zoom this quarter.
fi
Discussion Sections
Discussion sections offer additional opportunities to see
examples of Python programs, interact with instructors, and your
fellow students.

During the rst week of discussion sections, TAs will guide you
through installing Python, using our Jupyter Hub, and using
Gradescope to submit a homework assignment.

You may attend an alternate discussion section time slot if that


works better for you.

A discussion topic will typically run for a week and will be chosen
based on the upcoming homework assignments or exams.
fi
Jupyter Notebooks is rapidly gaining in popularity.
It is another technology you will use in this course.
Popularity of Jupyter Notebooks

https://octoverse.github.com

ECS32A
Discussion Boards
• TAs and Tutors will be present on Piazza 7 days a week for
help.

• Questions regarding the curriculum should be posted to


Piazza. Avoid e-mailing these questions. You will get prompter
answers on Piazza, and others will bene t.

• Piazza is a moderated forum. Public posts are curated for


educational value to students. We keep track of posting and
award up to 1% extra credit to the top posters.

• Do not publicly post your partial or complete solution


programs to the homework on our discussion boards! We
consider posting code cheating on the assignment. See the
next slide for what to do on Piazza.
fi
Help with homework on Piazza
Try and abstract the question to something general about
Python, and post that to Piazza.

If your program doesn’t work and you get a Python error


message, it is good to include that in a public post. The
single line of code it contains is usually enough to get help
from another student. Also, other students will bene t if they
run across the same error message.

If you have a Gradescope error, please include the output of


your program when you run it in IDLE and the corresponding
Gradescope error message.

As a last resort, or at the request of a TA, you can privately


post code. Make sure that your code is properly formatted in
the post. fi
Discord and Tutors
• This quarter we are also hosting a Discord server
where you can chat with students and student tutors.

• We usually have 15-20 student tutors! These tutors


were all once ECS32A students just like you. They
are on discord to hang out and answer your
questions. We will post schedule of their of ce
hours.

• You will also meet the tutors at our Stay Late and
Code Nights.
fi
Engaging with the Material
• Use our Piazza site to ask and answer questions.

• Use the interactive textbook, you can run and modify many of the code
examples. For additional practice with coding, consider doing the
exercises at the end of assigned chapters.

• Lectures will include links to Python Tutor demonstrations. These are links
to programs that you can step through in your own time.

• Lectures will include code demonstrations. If possible, type along in


IDLE. The nished programs are posted.

• On the Jupyter Hub, we will provide discussion notebooks and examples.


Also a "Core Python" notebook, which is a concise interactive code
reference on which you can expand.

• For practice taking exams, all Gradescope exams will have corresponding
Gradescope online sample exams with the same format and length.
fi
Getting started!
• Go to Canvas.

• Read the syllabus.

• Go to python.org and install the latest Python 3.

• Find the online textbook and your rst reading


assignment on Canvas.

• Your rst discussion section will cover installing and


using Python, using our Jupyter Hub, and submitting
homework to Gradescope using a short Welcome
assignment.
fi
fi
Python in Research

ECS32A
Race to Sequence the Human Genome

Human genome project

Huge public consortium Celera: Venter and Meyers


Took decades a biologist and a programmer
a couple years
Examples from my world: Genomics
Python Module

"Biopython is a set of freely available tools for biological


computation written in Python by an international team of
developers."
Thousands of published research papers use it
Python in Bioinformatics
my_program.py

Specialized programs
Big Data, Python, and Human Genomics
The Python Interpreter
& IDLE

ECS32A
First, a look at our abstract*
computer…

* reduced to essential details


Our Computer Model
Our Computer Model

• The Central Processing Unit is the heart of any


computer. It is what runs the programs that we write;
also called “CPU” or “the processor”.

• It is asking "What next?" billions of times per second.


Our Computer Model

• Main Memory stores working information that the CPU


needs in a hurry. These are programs and the data
they work with.

• Goes away when power is removed. So we use


something else for long term storage.
Our Computer Model

• Secondary memory is where our les live long term.


It’s much slower, but can store large amounts of
information even when the power is removed.

• Examples are disk drives, ash drives, and non-volatile


memory.
fl
fi
Our Computer Model

• Most computers can connect to a Network to send and


retrieve information.

• You can think of a network as a very slow place to store


and retrieve data that might not always be “up”. On the
internet instead of a lename we use a URL to locate data.
fi
Our Computer Model

• Input and Output Devices are the keyboard, touchpad,


screen, touchscreen, stylus, etc.

• These are all the ways people interact with the computer.

• In this class we will use the keyboard and the screen.


What is Programming?

• The programmer orchestrates these resources to do


something interesting.

• These instructions are given using a programming language

• This is mostly talking to the CPU answering the "What’s Next?"


question. Sometimes telling CPU to use the main memory,
secondary memory, network, or the input/output devices.
Terminology:
Interpreter and Compiler

• Our language, Python, like JAVA, C, C++, Perl, etc., is a formal high-
level programming language designed for humans to work with.

• However, the CPU only understands a non-readable binary machine


language designed only for hardware.

• Interpreters and compilers both convert a high level language into


machine language.

• Interpreters do this on-the- y every time the program is run.


Python is an interpreted programming language.

• Compilers do this once putting the machine language into a le to


be run later. It is assumed the program will be run many times so a
lot of time is spent optimizing. C and C++ are compiled languages.
fl
fi
Python Interpreter
Python, a high level
language
Machine
language

What What
A Python interpreter Next? Next?
interprets programs
line-by-line Central
Processing
Unit
Integrated Development and
Learning Environment
• IDLE is our Python interpreter.

• It responds to input (Python code) line-by-line.

• The >>> shell prompt is the Python interpreter’s way


of asking you, “What do you want me to do next?”
Python (IDLE) Install

https://www.python.org
(Try it)
Our First Line of Python

• This is the IDLE shell window, where we can interact with


the Python interpreter.
• In this window we use Python like an advanced calculator
to determine what small pieces of code do.
• This is not where we write and run full programs.
Our First Python Program

• This is an IDLE le (a.k.a. script) window.


• Select New File from the File menu.
• This is where you will write, save, and run your programs.
• Run a program by selecting Run Module from the Run menu.
fi

You might also like