agatsu_presentation/slides.md

5.8 KiB

class: center, middle

Introduction to Programming

Irene - Jun 11, 2023


Basics of Computers

Computers are made of three basic parts

  1. Processing
  2. Input/Output
  3. Storage

??? Start by talking about how a computer has three parts. Draw an analogy to the human body.

Draw this diagram on board to explain the interaction

-----------      ----------------         -------------
|  Input  | <--> |  Processing  |  <--->  |  Storage  |
-----------      ----------------         -------------
                       ^
                       |
                       v
                   ------------
                   | Output |
                   ------------

--

  • Processing is done by the CPU.
  • Input/Output devices are for instance: keyboard, mouse.

How do Computers Speak?

Computers use a different language than humans. Just like humans communicate in natural languages like Hindi, Kashmiri, English, etc, computers communicate in binary.

  • English: marker
  • Binary: 01101101 01100001 01110010 01101011 01100101 01110010

???

DO NOT dive into binary conversion.

Simply use electric signals as two states - hence 1, 0.


How does code run?

  • Computers read a piece of code from memory.
  • Each number is a special instruction.
  • The number tells the computer what to do.
  • The computer executes this and then moves on to the next instruction.
???

Use the menu analogy. We visited a restaurant some time ago.

Build a hypothetical machine. Create ASM for it.

0001 ADD
0010 SUB
0011 MUL
0100 DIV
0101 INP

Programming Languages

  • Early on, programs were written in binary.
  • Then to make things simpler, programs were written in Assembly.
  • And the progression continued to make higher and higher languages.

??? explain the transition

give examples of ADDR and 00101110

e.g.

01000010 01100001
ADD 0xff

--

Example code

name = input("What is your name?")
print("Welcome", name)

How do you create apps?

There are multiple languages that help us in various different tasks

--

  • General Purpose Languages are used for a variety of things

    • Python is used in Desktop Apps, Data Science, Machine Learning, Web Servers, etc.
    • JS is used for website development, backend development, etc.
    • Java is used for servers, Android Applications, etc.

--

  • Special Languages help us develop specific things.
    • HTML is used for creating content of websites.
    • CSS is used for styling webpages.
    • XML is used for storing data.

Python

Python is a general purpose programming language. It is a beginner friendly programming language. For this session, we will skip the installation but you can simply install it by downloading the setup from python.org.

We will be using an application called IDLE to run our code.

???

Open IDLE and explain how running the code works and how we can store files and run the code inside them. Introduce to some basic ideas like using interpreter as a calculator, stdout and thus print.


Memory and Variables

Memory is where our program stores data. It is different than Hard Disk as it is a temporary storage. When we write programs, we store tiny bits of data to this storage. We can access this data by variables.

*a = 100
print(a)

*b = "Jinal"
print(b)

???

Explain memory in depth. Drop into idle and run the code. Explain that we are storing data in the memory and print is the command to send it through to output


Data Types

Python has various data types. The basic data types available are:

  • Boolean
  • Integer
  • Float
  • String

???

Explain type conversion and introduce to int and float functions. Explain addition on types.


Task: Ask for two numbers and add them

--

str1 = input("Enter Number 1: ")
num1 = int(str1)

--

str2 = input("Enter Number 2: ")
num2 = int(str2)

--

total = num1 + num2
print(total)

Operators

There are various types of operators in python.

--

  • Arithmetic
    • + - * / % **

--

  • Comparison
    • == > >= < <=

--

  • Logical
    • and or not

Out of today's scope

  • Assignment

    • = += -= *= /= //= %= **= etc
  • Bitwise

    • | & ^ >> << ~
  • Membership

    • in, not in
  • Identity

    • is, is not

Conditionals

We can branch our code based on the result of conditions.

if condition:
    some_statements
elif condition_2:
    some_statements
elif condition_3:
    some_statements
else:
    some_statements

Small example to tie it all together

Write a program that asks the user to enter a number

  • If the number is divisible by 3 and 5, print "divisible by 3 and 5"
  • If the number is divisible by 3, print "divisible by 3"
  • If the number is divisible by 5, print "divisible by 5"
  • Else print the number

--

Solution

number = int(input("Enter a number: "))

if number % 3 == 0 and number % 5 == 0:
    print("divisible by 3 and 5")
elif number % 3 == 0:
    print("divisible by 3")
elif number % 5 == 0:
    print("divisible by 5")
else:
    print(number)

Some questions to try

  • Write a program to check if the user entered a vowel or a consonant

  • Write a program to print out the signum value of a function. If the number is negative, print -1, if it is zero, print 0, if it is positive, print 1.

  • (Math heavy) Take the x, y coordinates for two points and calculate whether the line through them touches the y-axis and where?


Thank you

Reach out to me at