Lecture - 0

What programmer?

programmer : a person who writes Computer programs.

"The single most important skill for a computer scientist is problem-solving."

Why python?

Because python is very popular among programmers. The language is easy to understand and not complicated.

Python features

- Uses an elegant syntax, making the programs you write easier to read.
- Python's automatic memory management frees you from having to manually allocate and free memory in your code.
- The language supports raising and catching exceptions, resulting in cleaner error handling.
- Runs anywhere, including Mac OS X, Windows, Linux, and Unix, with unofficial builds also available for Android and iOS.

Python ubiquity

Python is everywhere and is used by many companies, including Google, Yahoo!, and NASA.

  • Scripting
  • 3D Modelling (Blender)
  • Desktop Applications
  • Games (Pygame)
  • Scientific (ScyPy, Numpy)

Python editions

  • CPython :Classic Python
  • IronPython :Python for .NET
  • Jython :Java python able to blen with java
  • PyPy :Compile python the fastest

  • Print Hello world! print("Hello World!")

  • Try to print your name!

    print("Supawit saelim :)")
    print('wow !!!')




  • How to print numeric


    print("100.00")
    print('%d' %100)
    print('%d' %100.58)
    print('%f' %100.58)
    print('%.2f' %100.1554345)





  • How to print string + numeric


    print('My age is',21,'years')
    print('My age is %d years' %21)
    print('My age is '+str(21)+' years')
    print('My age is',10+11,'years')





  • How to print string + string


    print('My age is '+'21 years')
    print('My age is','21 years')
    print('My age is '+str(21)+' years')



  • Finally,Print numeric + numeric


    print(1 + 1)
    print(1.1 + 1.1)
    print(5 * 3)
    print(5 ** 2)
    print('%d' %(5**2))
    print(15 / 5 + 2)

Next lecture is about DataType Variable and Expression.



Lecture 1

DataType Variable and Expression




  • COMPUTER AND PROGRAM

    The physical devices that a computer is made of are referred to as the computer's hardware. The programs that run on a computer are referred to as software. Computers can do such a wide variety of things because they can be programmed. This means that computers are not designed to do just one job, but to do any job that their programs tell them to do. A program is a set of instructions that a computer follows to perform a task.

  • HOW COMPUTER STORE DATA

    All data stored on storage media – whether that’s hard disk drives (HDDs), solid state drives (SSDs), external hard drives, USB flash drives, SD cards etc – can be converted to a string of bits, otherwise known as binary digits. These binary digits have a value of 1 or 0, and the strings can make up photos, documents, audio and video. A byte is the most common unit of storage and is equal to 8 bits.




For example, if we want to store char ‘A’ in computer, the corresponding ASCII value will be stored in computer. ASCII value for capital A is 65. To store character value, computer will allocate 1 byte (8 bit) memory. 65 will converted into binary form which is (1000001) 2. Because computer knows only binary number system. Then 1000001 will be stored in 8-bit memory.









  • What's Assembly Language?

  • Each personal computer has a microprocessor that manages the computer's arithmetical, logical, and control activities. Each family of processors has its own set of instructions for handling various operations such as getting input from keyboard, displaying information on screen and performing various other jobs. These set of instructions are called 'machine language instructions'. A processor understands only machine language instructions, which are strings of 1's and 0's. However, machine language is too obscure and complex for using in software development. So, the low-level assembly language is designed for a specific family of processors that represents various instructions in symbolic code and a more understandable form.





HIGH LEVEL LANGUAGE

In the 1950s, a new generation of programming languages known as high-level languages began to appear. A high-level language allows you to create powerful and complex programs without knowing how the CPU works


ADVANTAGES OF HIGH-LEVEL LANGUAGES

The main advantage of high-level languages over low-level languages is that they are easier to read, write, and maintain. Ultimately, programs written in a high-level language must be translated into machine language by a compiler or interpreter. The first high-level programming languages were designed in the 1950s. Now there are dozens of different languages, including Ada, Algol, BASIC, COBOL, C, C++, FORTRAN, LISP, Pascal, and Prolog.


PROGRAMMING LANGUAGES


COMPILER




INTERPERTER






  • PROGRAM DEVELOPMENT CYCLE



The process of designed a program can be summaried in the following two steps
-understand the task that program is to perform
-Deter mine the steps that must be taken to perform the task


  • PSEUDOCODE

    Pseudocode is a way of expressing an algorithm without conforming to specific syntax rules. By learning to read and write pseudocode, you can easily communicate ideas and concepts to other programmers, even though they may be using completely different languages. Pseudocode is also a good


  • FLOWCHART

    A flowchart is a picture of the separate steps of a process in sequential order. It is a generic tool that can be adapted for a wide variety of purposes, and can be used to describe various processes, such as a manufacturing process, an administrative or service process, or a project plan.

FLOWCHART SYMBOLS






  • IPO

1. input is received from the user or from another program
2. the program processes the input
3. the program produces output



WHAT'S VARIABLES?

A variable is a named location used to store data in the memory. It is the basic unit of storage in a computer program. Each variable in Python has a specific type, which determines the possible values for that variable, the operations that can be performed on it,
and the meaning of the data that it stores.

fruit = 'apple'
fruit = 'banana'
fruit = 'orange'

Valid Variable Names

Case sensitive. like name, Name, and NAME are three different variables.
Must start with a letter or the underscore character (Can contain numbers).
Cannot start with a number.
Cannot contain any spaces.
Cannot use any of these symbols :'",<>/?|\()!@#$%^&*~-+


RESERVED WORDS




You can set variable names to be 3 types like this
1.camel case : UserInput
2.snake case : user_input
3.kebab case : user-input


  • DATA TYPES



NUMBERS

Number the simplest data type in Python. They can be integers, floating point numbers, or complex numbers. They are defined as int, float, and complex class in Python. Integers are whole numbers, positive or negative, without decimals, of unlimited length.
Floating point numbers are represented as decimals and are accurate up to 15 decimal places.

Try !

BOOLEAN



  • Boolean represent one of two values: True or False.
    Boolean values are often used to keep track of certain conditions, such as whether a game is running or whether a user can edit content on a web page.

STRINGS



  • String a sequence of characters.
    Strings are immutable, which means that elements of a string cannot be changed once it has been assigned.
    However, a new string can be assigned to a different variable.
    Strings can be created using single quotes or double quotes.
    how to use single quotes or double quotes inside a string

PYTHON OPERATORS

Operators are used to perform operations on variables and values.
Python divides the operators in the following groups:
- Arithmetic operators
- Assignment operators
- Comparison operators
- Logical operators
- Identity operators
- Membership operators
- Bitwise operators

let's see !


  • ARITHMETIC OPERATORS


    Arithmetic operators are used with numeric values to perform common mathematical operations:
    Operator Name Example
    + Addition x + y
    - Subtraction x - y
    * Multiplication x * y
    / Division x / y
    % Modulus x % y
    ** Exponentiation x ** y
    // Floor division x // y




OPERATOR PRECEDENCE


Operator precedence determines the grouping of terms in an expression,
which affects how an expression is evaluated.
Operator Description
() Parentheses
** Exponentiation
~ + - Complement, unary plus and minus (method names for the last two are +@ and -@)
* / % // Multiplication, division, remainder and floor division
+ - Addition and subtraction
> >= < <=Comparison operators
== != Equality operators
= %= /= //= -= += *= **= Assignment operators
is is not Identity operators
in not in Membership operators
not or and Logical operators


COMPARISON OPERATORS


  • Comparison operators are used to compare two values:
    Operator Name Example
    == Equal x == y
    != Not equal x != y
    > Greater than x > y
    < Greater than or equal to x < y
    >= Less than x >= y
    <= Less than or equal to x <=y


LOGICAL OPERATORS


  • Logical operators are used to combine conditional statements:
    Operator Description Example
    and Returns True if both statements are true
    or Returns True if one of the statements is true
    not Reverse the result, returns False if the result is true


BITWISE OPERATORS

Let x = 10 (0000 1010 in binary) and y = 4 (0000 0100 in binary)
OPERATORS MEANING EXAMPLE
& Bitwise AND x & y = 0 (0000 0000)
| Bitwise OR x | y = 14 (0000 1110)
^ Bitwise XOR x ^ y = 14 (0000 1110)
~ Bitwise NOT ~x = -11 (1111 0101)
>> Bitwise right shift x >> 2 = 2 (0000 0010)
<< Bitwise left shift x << 2 = 40 (0010 1000)


AISSIGNMENT OPERATORS

Let x = 10 (0000 1010 in binary) and y = 4 (0000 0100 in binary)
OPERATORS EXAMPLE EQUALS TO
= x = 5 x = 5
+= x += 3 x = x + 3
-= x -= 3 x = x - 3
*= x *= 3 x = x * 3
/= x /= 3 x = x / 3
%= x %= 3 x = x % 3
&= x &= 3 x = x & 3
//= x //= 3 x = x // 3
**= x **= 3 x = x ** 3
|= x |= 3 x = x | 3
^= x ^= 3 x = x ^ 3
>>= x >>= 3 x = x >> 3
<<= x <<= 3 x = x << 3


IDENTITY OPERATORS



  • Identity operators are used to compare the objects, not if they are equal,
    but if they are actually the same object, with the same memory location:
    Operator Description Example
    is Returns True if both variables are the same object
    is not Returns True if both variables are not the same object


MEMBERSHIP OPERATORS


Membership operators are used to test if a sequence is presented in an object:
Operator Description Example
in Returns True if a sequence with the specified value is present in the object
not in Returns True if a sequence with the specified value is not present in the object









  • INPUT


  • Python allows for user input.
    That means we are able to ask the user for input.
    The method is a bit different in Python 3.6 than Python 2.7.
    Python 3.6 uses the input() method.
    Python 2.7 uses the raw_input() method.
    Example
    if we want to ask the user for a name, we can execute the following code:
    input("Enter your name: ")
    input return data type is string
  • Try


INPUT NUMBERS

By default the input function takes the input as a string. But we can convert the input to other data types like int, float etc. Example num1 = int(input("Enter first number: ")) num2 = int(input("Enter second number: "))
sum = num1 + num2
print("The sum is", sum)

Try


READ MULTIPLE VALUES FROM KEYBOARD


FINALLY , COMMENT

Comments can be used to explain Python code. Comments can be used to make the code more readable. Comments can be used to prevent execution when testing code. Comments starts with a # and Python will ignore them. or starts with a triple quotes """

Thanks !

See you next time

If you have any questions, please feel free to contact me.