0% found this document useful (0 votes)
6 views24 pages

Slides 1

Uploaded by

bruceayim30
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views24 pages

Slides 1

Uploaded by

bruceayim30
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Class 1 - Introduction to Programming

MISE Summer Programming Camp 2023


Why programming?

Virtually everything in the modern world has a software (program) component.

Programming is an essential skill in many scientific areas


Programming in the Real-World

Taken from Princeton COS 126 slides


What will you learn?

1. How to create simple programs

2. How to learn more on your own


Class logistics
● Weekly homeworks out after each class
● Due Friday of the following week
For: ● Posted on the website
Homework
● Announcements ● Try to finish homeworks on time, but if you
● Questions after class are stuck, ask for help on piazza!
● Posting class recordings ● Optional small class project later (early
June). You can work in groups for that

Website https://www.cs.princeton.edu/~pparedes/teaching/mise/summer23/ Please ask questions during class! Send private


messages through zoom or unmute yourselves!
What is a program?
Collection of well defined instructions that describe a task

To bake a cake:
1. Combine sugar and butter
2. Beat in eggs
3. Add flour
4. Add milk
5. Bake in oven
How do we tell a computer what to do?
To communicate amongst ourselves we use human languages (for example, English)

To communicate with computers we will use a programming language, namely Python


What does a python program look like?
Suppose we want to write a program that checks if a number is prime:

Look for all numbers between 2 and target


If we find a divisor:
Then the number isn’t prime, report that

Otherwise:
The number is prime! Report that
Program Abstraction

Input Stream

input()

Python Program

print()

Output Stream
First demo: my first program

Go to: https://www.programiz.com/python-programming/online-compiler/

Learning goals:

1. How to print/read data


2. Python as a calculator
3. What is a variable
itempool.com/mise23/live

Pop Quiz 1:

What is the output of the following program:


What we just learned

● Printing text to the shell

● What is a variable, how to create modify and use one

● Reading input from the user in the shell

● How to use basic math operators


You have to follow
the right syntax! Produces an error

Here is an example of wrong code

To fix we need to change line 3


Basic Data Types in Python

● Integer - represents integers eg. 2, -20, 9999999


● Float - represents decimal numbers eg. 2.0, -3.99, 568.98
● String - represents a sequence of characters eg. “Hello”, “#Hi!”, “42”
○ Note the pair of double quotes around the sequence
● Boolean - represents true or false values eg. True, False
○ Capitalization is important here!
Second demo: examples with data types

Learning goals:

1. What is a data type


2. How to use strings
3. How to manipulate data types
The type() instruction!
If you ever need to know the type of something, you can use the type() instruction to do that, like so:
Second demo continued
Pop Quiz 2:

What is the output of the following program:


Pop Quiz 3:

What is the output of the following program:


One more demo: A polite program

Learning goals:

1. Writing a program with a purpose


Pop Quiz 4:

If we run this program and write the number "3" on the terminal, what would be its output?
One more demo: A polite program now complete

Learning goals:

1. Writing a program with a purpose


Homeworks - Using CodeForces

A website where you can submit programs and


get immediate feedback

Go to: https://codeforces.com/group/K1Fxw6skwV/contests
What’s next?

Homework will be posted on Piazza by tomorrow! You won’t learn anything if you
don’t try the homeworks

Class 2: Functions and Conditionals

How to create code modules

How to have different outcomes based on the input

You might also like