Introduction to Computing with Python - lecture 1

Today

目录

Course Info

What is a Computer

Data Representation

Programming Languages

Python 3

Stages in Problem Solving

Course Goals

·Introduction to computer science and software development

·Present methods for problem solving

·Acquiring Python 3 programming skills

Learning and understanding tools for problem solving using a computer in science and engineering.

 

Motivation

Why do I need this?How would this course benefit me?

 

Problem Solving

Introduction to Computing with Python - lecture 1_第1张图片

Mathematics, Statistics

Monte Carlo Method Using randomness in problem solving

Introduction to Computing with Python - lecture 1_第2张图片    

Introduction to Computing with Python - lecture 1_第3张图片

Data Visualization 

 

Physics: DEM and CFD

Introduction to Computing with Python - lecture 1_第4张图片

Discrete Element Method (DEM) for simulating structural failure 

Introduction to Computing with Python - lecture 1_第5张图片Computational Fluid Dynamics (CFD) simulation for evaluating air velocity around a cyclist

Physics: Evolution of a Cough

Introduction to Computing with Python - lecture 1_第6张图片

 

Introduction to Computing with Python - lecture 1_第7张图片 

Biology: Protein Folding

Introduction to Computing with Python - lecture 1_第8张图片

 

Neural Style Transfer

 Machine Learning

Genetic Algorithms (GA) are a mathematical model inspired by the famous Charles Darwin’s idea of natural selection. The natural selection preserves only the fittest individuals, over the different generations.

Introduction to Computing with Python - lecture 1_第9张图片

Introduction to Computing with Python - lecture 1_第10张图片 

WHAT IS A COMPUTER ?

Where did it All Begin?

  • Historically, there was always a need to make calculation  faster and more accurately.
  • Abacus:
    • Better than counting fingers
    • Remembers” results
    • Can be used for: × ÷ + −
    • Origin: China

Introduction to Computing with Python - lecture 1_第11张图片 

 

Mechanical Calculator

  • Blaise Pascal - Famous French scientist. Made significant discoveries in the fields of Physics and Mathematics.
  • Invented in 1642 (aged 19) the “Pascalin”: a mechanical calculator for addition and subtraction.

Introduction to Computing with Python - lecture 1_第12张图片 

 Mechanical Computer

  • Introduction to Computing with Python - lecture 1_第13张图片
  • Charles Babbage’s “Difference Engine” – 1822, built after his death.
  • Calculation speed: 12 operations per minute!
  • Introduction to Computing with Python - lecture 1_第14张图片Introduction to Computing with Python - lecture 1_第15张图片Introduction to Computing with Python - lecture 1_第16张图片
  • In 1833, together with Ada Lovelace (historically, the first “computer programmer”) invented an “analytical engine” capable of running instructions based on punch-cards.

  • A computer is a device that manipulates information or data.
  • Can receive input, perform calculations and display or store the results.
  • Does exactly what it is instructed to do, not less and not more.
  • Can be mechanical or electronic.
  • Introduction to Computing with Python - lecture 1_第17张图片

 

 Hardware and Software

Hardware:Introduction to Computing with Python - lecture 1_第18张图片
•    The physical components of a computer
•    Inside the computer:
Processor (CPU), memory, GPU.
•    Outside the computer:
Mouse, keyboard, display, speakers
•    Software:Introduction to Computing with Python - lecture 1_第19张图片Introduction to Computing with Python - lecture 1_第20张图片

•    Sequence of commands that use the hardware.

 

 HARDWARE COMPONENTS

 CPU –   Central Processing Unit

  • The main component responsible of computation (Central Processing Unit)
  • Receives commands for processing:
    • Arithmetic operations (addition, subtraction, multiplication, etc.)
    • Input/output operations (reading memory)
    • Evaluating conditions (if some condition met, then do something)

Introduction to Computing with Python - lecture 1_第21张图片 Introduction to Computing with Python - lecture 1_第22张图片Introduction to Computing with Python - lecture 1_第23张图片

 

 Memory

The Memory is a special hardware component in which the CPU can read from and write to.

Difference between types of memory:

  • Capacity – how much information can be stored.
  • Mobility – memory is connected permanently or can be used between different computers.
  • Survivability – information is stored or deleted after turning off the machine.
  • Price.

Main Memory - RAM 

  • Fast
  • Expensive
  • Compact (compared to secondary memory)
  • Common Capacity: 4GB, 8GB, 16GB, 32GB

Introduction to Computing with Python - lecture 1_第24张图片 Introduction to Computing with Python - lecture 1_第25张图片

 

 Secondary Memory

  • Slow
  • Cheap
  • Higher capacity: 1TB - 12TB

Introduction to Computing with Python - lecture 1_第26张图片 Introduction to Computing with Python - lecture 1_第27张图片Introduction to Computing with Python - lecture 1_第28张图片

 

 

 

 

 

Communication  Channel  (BUS) 

  • Different hardware uses the same communication channel to pass information.

 

OPERATING SYSTEM Introduction to Computing with Python - lecture 1_第29张图片

 

  • The “glue” between hardware and software
  • Passes information
    • For example: reading words from a file stored in memory
  • Passes commands:
    • For example: command to present an image on the screen

 

Introduction to Computing with Python - lecture 1_第30张图片

 Operating System: Example

What happens when you type the string “Hello” in a Word document?

  1. The Keyboard recognizes a keystroke
  2. The Keyboard passes the corresponding character to the Operating System
  3. The Operating System passes the character to the Word Application
  4. The Word Application sends via the Operation System a request to display the types character.
  5. The Operating System passes the request to the Display

 

 

DATA IN MEMORY

What is Data?

  • Anything we would like to store
    • Images
    • Music
    • Movies
    • Documents
  • Computer code, software, applications
    • The operating system, Microsoft Office, drivers

How is Data Stored? 

  • We all know that computers need power.
  • How can we use that power to represent data?

Introduction to Computing with Python - lecture 1_第31张图片

 

 

  • Computer memory is made of ones (1) and zeros (0) which are called bits. Generally, 0 is represented by low voltage and high voltage represents 1.
  • Different types of data are stored using encoding.
  • Binary encoding – using sequences of bits to store more complicated types of data.

Introduction to Computing with Python - lecture 1_第32张图片 

 

 Base-10 Number Representation

 

  • The numeral system we use since ancient civilizations. Likely since there are ten fingers on two hands.
  • Each digit has 10 possible values: 0-9
  • Introduction to Computing with Python - lecture 1_第33张图片

  • Exercise:

What is the representation of 452 in powers of 10?

 

Base-2 Number Representation 

 Introduction to Computing with Python - lecture 1_第34张图片

 

 

Binary System 

  • Each bit is given different weight based on location.
  • This is known as the Binary System (base 2).
  • In binary, instead of using powers of 10 to define the “weight” of a digit, we use powers of 2:

Introduction to Computing with Python - lecture 1_第35张图片 

 

  • It is possible to represent any number in this system.

Binary Number Representation

 

 More Examples

 

 

 Byte

  • For sake of simplicity, a sequence of 8-bits is referred to as a single Byte.
  • A Byte can get 256 different values. These values are 0-255.

Introduction to Computing with Python - lecture 1_第36张图片 

 

 Numbers in Memory

  • Bit is the smallest unit of memory inside a computer. A bit represents a binary digit.
  • Byte is a unit composed of 8 bits.
  • Every piece of information is stored as a sequence of ones and zeros. Whole numbers are represented in Binary as discussed before.

Introduction to Computing with Python - lecture 1_第37张图片

 

 

 Other Types of Data

  • Thus far we discussed representation of numbers inside the computer.
  • How can we represent other types of data in a computer?

 

Introduction to Computing with Python - lecture 1_第38张图片

 

Images 

 Images - RGB 

  • Each number represents a different color or shade: 0 – black, 255 - white

Introduction to Computing with Python - lecture 1_第39张图片 Introduction to Computing with Python - lecture 1_第40张图片

Introduction to Computing with Python - lecture 1_第41张图片

 

 Music

  • Each number represents different note pitch and length

 

 

 Most Important –  Code!

  • It is possible to represent different commands using binary encoding. For example:

0 – read a number from memory 1 – add two numbers

01 – write number to memory 10 – subtract two numbers

  • Each CPU has its own “language” – numbers that resemble CPU operations.

This is called Machine Code.

  • This is the only language a processor can “understand”.

PROGRAMMING LANGUAGES 

Machine Code

  • Machine code is the language in which hardware uses for communication.
  • Operations such as writing\reading from memory, multiplication, etc.
  • It is incredibly difficult to write software in machine code.
  • This is easy for a computer, hard for a human.

 

High-Level Programming Language 

  • Introduction to Computing with Python - lecture 1_第42张图片
  • High-Level Programming Languages allow us to write programs in an easier and more human-readable way.
  • There are special tools that translate high-level code into lower-level code or machine code so that the computer will understand what operations it needs to execute.
  • We will use a high-level programming language called Python 3.

 

 

A program that displays the text “Hello World!” in different programming languages:

  • In C:

Introduction to Computing with Python - lecture 1_第43张图片 

  • In Java:

Introduction to Computing with Python - lecture 1_第44张图片 

 

  • And now in Python:

print(‘Hello world!’)

 

PYTHON 3

Simple Example

Introduction to Computing with Python - lecture 1_第45张图片

  • Code:

  • Output:

 

 

STEPS IN PROBLEM SOLVING

Problem Solving: The Steps

  • Understand the problem. Identify the Input à Output

  • Design an algorithm (a recipe) to  solve it

  • Start coding

 

 

 

Problem Solving: Cashier 

Example:

Write a program which receives a series of purchases, prints the current total and tells the cashier to go home when the total reaches over $1000.

 Problem Solving: Algorithm

     1.Define a counter which keeps track of the current sum.

     2.Get the cost as input  Add the cost to the sum Display the sum

     3.If the sum is smaller than $1000, repeat

     4.If not, display “Go Home!”

 Introduction to Computing with Python - lecture 1_第46张图片

 

Problem Solving: Code

Introduction to Computing with Python - lecture 1_第47张图片 

 

 Actual Coding and Debugging?

Soon….

Introduction to Computing with Python - lecture 1_第48张图片

 

Introduction to Computing with Python - lecture 1_第49张图片

 

你可能感兴趣的:(python萌新级教程,python)