1 of 37

Go to Moodle and Take Quiz 2

Opens at 9:30

Time: 8 minutes

Password:

Comp 118: Introduction to Programming

2 of 37

EDUCATION IS WHAT REMAINS

AFTER you have FORGOTTEN

everything that you LEARNED IN SCHOOL

Wisdom of the Day

Real school is the school of life

Be a lifelong learner

3 of 37

Weather News

2025 4th warmest year in U.S. history was full of deadly weather extremes

https://www.climatecentral.org/climate-matters/2025-in-review-us-temperatures

4 of 37

Globally, 2025 was the 3rd warmest on record, after 2023 and 2024

https://www.ecmwf.int/en/about/media-centre/news/2025/2025-third-warmest-year

  • Global temp in 2025 was only marginally (0.01°C) cooler than 2023, and 0.13°C cooler than 2024, which remains the warmest year on record.
  • Last three years were three warmest on record, WMO confirms
  • Average temperature has exceeded 1.5 C for longest period on record
  • Paris accord temperature goal could be breached this decade

5 of 37

Heat Wave Fuels Massive Wildfire In Australia

Temperatures rose as much as 34 degrees above average in Victoria, Australia, where wildfires have already destroyed 750,000 acres and more 100 homes and buildings.

6 of 37

Lessons from Weather/Climate

  • Look at the big picture
  • Don’t be fooled by local and temporary conditions
  • Don’t be selfish
  • We are all connected
  • Poor countries suffer more but nobody is immune
  • The earth is burning, boiling, and sinking both physically and spiritually
  • We are destroying the planet and the humanity

7 of 37

8 of 37

Class Norms

https://docs.google.com/document/d/1kaooyF2U1JpqbACbTlxTVbfxhhgjkanAAMeAzPl4fpY/edit?usp=sharing

9 of 37

Looking Ahead

  • First History Essay is due Mon, Jan 19 (midnight)
  • First set of CodeLab exercises due Thu, Jan 22 (midnight).
  • Lab 0 due Sun, Jan 25 (midnight)
  • MSSC schedule will be announced soon

10 of 37

Reminders

  • No make-up for quizzes
  • AI not allowed
  • For labs, do not use anything we have not learned in class. If you do, you will be required to give an oral explanation of your code

11 of 37

Today’s Agenda

  • Quick logistics review: course website,Moodle, textbook, CodeLab, onlineGDB
  • POGIL activity on Intro to Python.
    • Go to https://csits.kenyon.edu/
  • Come back and go over as a group
  • Discuss some general concepts about programming
  • For next Tuesday, read sections 2.1-2.7 in the textbook
  • Quiz 3 will include questions from today and next reading

12 of 37

Login to CodeLab and do a few exercises

13 of 37

Main Goal of the Course

  • Learn algorithmic and computational modes of thinking
  • Introduction to the art of computational problem solving
  • Learn basic principles and elements of programming in the context of two important languages

https://runestone.academy/ns/books/published/KenyonComp118Sp26/GeneralIntro/intro-TheWayoftheProgram.html

14 of 37

Topics

  • Python Programming
  • C++ Programming
  • Algorithm Design
  • Debugging
  • Good programming Practices

15 of 37

The Python programming language

  • Python is an example of a high-level language; other high-level languages you might have heard of are C, C++,C#, Java, Pascal, PHP, and many more …
  • The machine actually executes a low-level language. This is machine code, the actual language of the hardware.
  • There must be a special program to convert the high-level code into something the machine can execute:
    • Interpreter - a (low-level) program that reads the high-level code and interpretes it, executing it line by line, alternately reading lines and performing computations. This is what Python does.
    • Compiler - a program that translates the entire high-level language code into low-level language code that the machine can execute. This is how C++ works.

Which way would be faster?

16 of 37

Compiler

  • Convert entire program to machine code
  • Execute machine code on cpu

Source code (program)

Input x

x= x + 1

output x

Compiler

Machine code (program)

01010010110

CPU

(executes)

Input�data

Output�data

17 of 37

Translator

Source code (program)

Input x

x= x + 1

output x

Interpreter

CPU

(executes translator)

Input�data

Output�data

Interpreter reads one line at a time and executes the operation.

18 of 37

CPU

19 of 37

Computers are machines

  • Execute a set of instructions that describe a process
  • Types:
    • Fixed Program - always same program
      • Calculator
      • Microwave oven
      • ?
    • Stored Program computer - machine stores programs and executes them
      • Laptop
      • Desktop

20 of 37

Stored Program Computer

  • sequence of instructions stored inside computer
    • built from predefined set of primitive instructions�1) arithmetic and logic�2) simple tests�3) moving data
  • special program (interpreter) executes each instruction in order
    • use tests to change flow of control through sequence
    • stop when done

21 of 37

WHERE THINGS GO WRONG-3 Types of Errors: T-P-S

  • Syntax errors
    • Violation of grammar/structural rules
    • Common and easily caught (by compiler/interpreter)
  • Run-time errors
    • Show up while running program
    • Program crashes/halts
  • Logic/Semantic Errors
    • Program runs and gives an answer but different than expected
    • Program behaves differently from what the programmer intended�

Car Analogy to explain types of errors

  • Car won’t start
  • Car runs but crashes
  • Car runs and arrives at a place but different from the intended destination

22 of 37

Foundations of Programming

  • Alan Turing (1912-1954) showed anything can be computed with only 6 primitive operations: Turing Machine, basic model of computation.

  • Modern programming languages have many convenient primitives built on basic primitives to make programming easier.

  • It turns out that anything that you can compute in one language you can compute in any other language.

23 of 37

Aspects of Programming Languages

  • Language primitives
    • English: words
    • Programming - numbers, strings, operators (tokens), keywords

24 of 37

Goal

  • Learn the syntax and semantics of a PL
  • Use those elements to translate “recipes” for solving a problem into a form that the computer can use to do the work for us
  • Learn computational modes of thought to enable us to leverage a suite of methods to solve complex problems
  • Analogy with human language: Knowing the grammar and syntax for a language is necessary but not sufficient to write meaningful/useful/beautiful essays, articles, books, poems

25 of 37

Python Programs

  • a program is a sequence of instructions: definitions and commands
    • definitions evaluated
    • commands executed by Python interpreter in a shell
  • commands (statements) instruct interpreter to do something
    • can be typed directly in a shell or stored in a file that is read into the shell and evaluated

26 of 37

Python Objects

  • programs manipulate data objects (values)
  • objects have a type that defines the kinds of things programs can do to them
  • objects are
    • scalar (cannot be subdivided, also called literals)
    • non-scalar (have internal structure that can be accessed)

27 of 37

Scalar Objects (Literals)

  • int – represent integers, ex. 5
  • float – represent real numbers, ex. 3.27
  • bool – represent Boolean values True and False
  • NoneType – special and has one value, None
  • can use type() to see the type of an object� In [1]: type(5)� Out[1]: int�� In [2]: type(3.0)� Out[2]: float

When you type this

The type is shown

28 of 37

Type Conversions (Casting)

  • can convert object of one type to another
  • float(3) converts integer 3 to float 3.0
  • int(3.9) truncates float 3.9 to integer 3

29 of 37

Print to console

To show output from code to a user, use print command�

In [11]: 3+2�Out[11]: 5�

In [12]: print(3+2)�5

No “out” because nothing in returned,

Just something printing

30 of 37

Expressions

  • combine objects and operators to form expressions
  • an expression has a value, which has a type
  • syntax for a simple expression

<object> <operator> <object>

31 of 37

Arithmetic OPERATORS on ints and floats

  • i+j ➞ the sum
  • i-j ➞ the difference
  • i*j ➞ the product
  • i/j ➞ division
  • i//j ➞ int division
  • i%j ➞ the remainder when i is divided by j
  • i**j ➞ i to the power of j

- if both are ints, result is int

- if either or both are floats, result is float

Result is float

result is int, quotient without remainder�

32 of 37

Simple Operations

  • parentheses used to tell Python to do these operations first
    • 3*5+1 evaluates to 16
    • 3*(5+1) evaluates to 18�
  • operator precedence without parentheses
    • **
    • *
    • /
    • + and – executed left to right, as appear in expression>

33 of 37

Variables and Assignments

  • equal sign is an assignment of a value to a variable name�
  • pi = 3.14159
  • pi_approx = 22/7
  • value stored in computer memory
  • an assignment binds name to value
  • retrieve the value by invoking the variable name

variable

value

If we use 22//7, value of expression is 3

34 of 37

Expressions

  • why give names to values of expressions?
  • reuse names instead of values
  • easier to change code later

pi = 3.14159�radius = 2.2�area = pi*(radius**2)

35 of 37

= sign in Programming vs Math

In programming, you do not “solve for x”

pi = 3.14159�radius = 2.2�# area of circle�area = pi*(radius**2)�radius = radius+1

36 of 37

CHANGING BINDINGS

  • can re-bind variable names using new assignment statements
  • value for area does not change until you tell the computer to do the calculation again

pi = 3.14�radius = 2.2�area = pi*(radius**2)�radius = radius+1

37 of 37

Python Variable Names

The Rules

  • Variables names must start with a letter or an underscore, such as:
    • _underscore
    • underscore_
  • The remainder of your variable name may consist of letters, numbers and underscores.
    • password1
    • n00b
    • un_der_scores
  • Names are case sensitive.
    • case_sensitive, CASE_SENSITIVE, and Case_Sensitive are each a different variable.