Section

  • General

  • Open allClose all

  • Instructions: Clicking on the section name will show / hide the section.

  • This section

    TOPIC 1: INTRODUCTION TO PROBLEM SOLVING

    LEARNING OUTCOMES

    By the end of this topics, you will be able to:

    1.      Explain the essence of computational problem solving

    2.     Explain what a computer algorithm is

    3.     Describe about program development life cycle




    1.0 ALGORITHMIC PROBLEM SOLVING

    Algorithms, building blocks of algorithms (statements, state, control flow, functions),  notation (pseudo code, flow chart, programming language), algorithmic problem solving,  simple strategies for developing algorithms (iteration, recursion). Illustrative problems: find  minimum in a list, insert a card in a list of sorted cards, guess an integer number in a  range, Towers of Hanoi.

     

    1.1  Algorithms

    What is algorithm?

    An algorithm is a collection of well-defined, unambiguous and effectively computable instructions ,if execute it will return the proper output.

    well-defined- The instructions given in an algorithm should be simple and defined well.

    Unambiguous- The instructions should be clear,there should not be ambiguity .

    Effectively computable- The instructions should be written step by step ,which helps  computer to understand the control flow .

    We often use algorithm in our day-to-day life,but when and how?

    Our cooking receipe

    Our daily routine as a student

    When we buy something

    When we go outing

    Our class routine

    How it helps?


    How an algorithm should be?

    It should be in simple English,what a programmer wants to say. It has a start,a middle  and an end. Probably an algorithm should have,

    Start

    1.       In the middle it should have set of tasks that computer wants to do and it should be in  simple English and clear.

    2.       To avoid ambiguous should give no for each step.

    Stop

     

    1.2 PROGRAM DEVELOPMENT LIFE CYCLE

    When we want to develop a program using any programming language, we follow a sequence of steps. These steps are called phases in program development. The program development life cycle is a set of steps or phases that are used to develop a program in any programming language.

    Generally, the program development life cycle contains 6 phases, they are as follows:

    • Problem Definition
    • Problem Analysis
    • Algorithm Development
    • Coding & Documentation
    • Testing & Debugging
    • Maintenance

                                                                                         

                                                                         
    Summary

    In this topic, you have learnt that on how to solving a problem.

    When solving a computational problem, either suitable existing algorithms may be found or new algorithms must be developed. Example, for the Traveling Salesman problem, there are various (nontrivial) algorithms that can be utilized, as mentioned, for solving problems with tens of thousands of cities. Finally, for the game of chess, since it is infeasible to look ahead at the final outcomes of every possible move, there are algorithms that make a best guess at which moves to make. Algorithms that work well in general but are not guaranteed to give the correct result for each specific problem are called heuristic algorithms.


    Program Implementation

    Then, you are able to design decisions provide general details of the data representation and the algorithmic approaches for solving a problem. The details, however, do not specify which programming language to use, or how to implement the program. That is a decision for the implementation phase. Since we are programming in Python, the implementation needs to be expressed in a syntactically correct and appropriate way, using the instructions and features available in Python.


    Program Testing

    As humans, we have abilities that far exceed the capabilities of any machine, such as using common sense reasoning, or reading the expressions of another person. However, one thing that we are not very good at is dealing with detail, which computer programming demands. Therefore, while we are enticed by the existence of increasingly capable computing devices that unfailingly and speedily execute whatever instructions we give them, writing computer programs is difficult and challenging. As a result, programming errors are pervasive, persistent and inevitable. However, the sense of accomplishment of developing software that can be of benefit to hundreds, thousands, or even millions of people can be extremely gratifying. If it were easy to do, the satisfaction would not be as great.

     

    Given this fact, software testing is a crucial part of software development. Testing is done incrementally as a program is being developed, when the program is complete, and when the program needs to be updated.

      By refer to this video lecture, you will get better understanding in this topic.

    Duration: 1 hour

    • Self-Check 1.1: Test Yourself(Duration 2 hours) Quiz
      Restricted Not available unless: The activity Topic 1- Video Lecture (1 hour) is marked complete
    • Restricted Not available unless: The activity Self-Check 1.1: Test Yourself(Duration 2 hours) is marked complete
    View only 'Topic 1'
  • View only 'Topic 2'
  • LEARNING OUTCOMES

    By the end of this topics, you will be able to:

    1.  Discuss program design concepts

    2. Explain method use for programming design

    3. Show an application use in programming

     

    3.1 PROGRAM DESIGN CONCEPT

    Now that computational problem solving and computer programming have been discussed, we turn to the Python programming language and associated tools to begin putting this knowledge into practice. Python has a simple syntax. Python programs are clear and easy to read. At the same time, Python provides powerful programming features, and is widely used. Companies and organizations that use Python include YouTube, Google, Yahoo, and NASA. Python is well supported and freely available at www.python.org.

     

    3.2 The IDLE Python Development Environment

    IDLE is an integrated development environment (IDE). An IDE is a bundled set of software tools for program development. This typically includes an editor for creating and modifying programs, a translator for executing programs, and a program debugger. A debugger provides a means of taking control of the execution of a program to aid in finding program errors.

    Python is most commonly translated by use of an interpreter. Thus, Python provides the very useful ability to execute in interactive mode. The window that provides this interaction is referred to as the Python shell. Interacting with the shell is much like using a calculator, except that, instead of being limited to the operations built into a calculator (addition, subtraction, etc.), it allows the entry and creation of any Python code.


    3.3 APPLICATIONS IN PROGRAMMING ENVIRONMENT

    The Python Standard Library is a collection of built-in modules, each providing specific functionality beyond what is included in the “core” part of Python. For example, the math module provides additional mathematical functions. The random module provides the ability to generate random numbers, useful in programming, as we shall see. (Other Python modules are described in the Python 3 Programmers’ Reference.). In order to utilize the capabilities of a given module in a specific program, an import statement is used


    SUMMARY

    IDLE is an integrated development environment (IDE). An IDE is a bundled set of software tools for program development. This typically includes an editor for creating and modifying programs, a translator for executing programs, and a program debugger. A debugger provides a means of taking control of the execution of a program to aid in finding program errors.

                                                                        

                                                                              


     

    Refer to the 0.5 hour video lecture, so we will have 0.5 hour Q and A session through online. Pls listen the video lecture carefully.

    View only 'Topic 3'
  • LEARNING OUTCOMES

    ♦          Explain and use the syntax and semantics

    ♦          Explain the formatting output statement

    ♦          Explain the basic input and output statement


    4.1 INTRODUCTION TO SYNTAX AND SEMANTICS

    Execute Python Syntax

    Python syntax can be executed by writing directly in the Command Line:

    Shape, rectangle

Description automatically generated


    Or by creating a python file on the server, using the .py file extension, and running it in the Command Line:


     


    4.2 INTRODUCTION TO BASIC I/O STATEMENTS

    Python Indentation

    Indentation refers to the spaces at the beginning of a code line. Where in other programming languages the indentation in code is for readability only, the indentation in Python is very important.

    Python uses indentation to indicate a block of code. Example

    if 5 > 2:

      print("Five is greater than two!")

    Output




    Python will give you an error if you skip the indentation:

    if 5 > 2:

    print("Five is greater than two!")

    Output


     

    The number of spaces is up to you as a programmer, but it has to be at least one:

    if 5 > 2:

     print("Five is greater than two!") 

    if 5 > 2:

            print("Five is greater than two!")

    Output


     


    SUMMARY

    In this topic you have learnt on how

    · Write the program using formatting input and output in Python.

    · Program debugging- process of finding and correcting errors (“bugs”) in a computer program.

    · Programming errors- inevitable during program development. Syntax errors are caused by invalid syntax (for example, entering prnt instead of print). Since a translator cannot understand instructions containing syntax errors,

    ·Translator terminate when encountering such errors indicating where in the program the problem occurred.

    · Semantic errors (generally called logic errors) are errors in program logic.


                                                                   

    ***Duration for the video lecture is 1 hours

    1 hour for lecture and the remaining is Q and A session

                                                 


    View only 'Topic 4'
  • LEARNING OUTCOMES

    By the end of this topic, you will be able to:

    ♦          Describe and perform variable assignment

    ♦          Describe real number and floating point format

    ♦          Describe string and character

     

    5.1 Built-in Data Types

    In programming, data type is an important concept. Variables can store data of different types, and different types can do different things. Python has the following data types built-in by default, in these categories.

    A data type is a set of values, and a set of operators that may be applied to those values. For example, the integer data type consists of the set of integers, and operators for addition, subtraction, multiplication, and division, among others. Integers, floats, and strings are part of a set of predefined data types in Python called the built-in types.

    Data types prevent the programmer from using values inappropriately. For example, it does not make sense to try to divide a string by two, 'Hello' / 2. The programmer knows this by common sense. Python knows it because 'Hello' belongs to the string data type, which does not include the division operation. The need for data types results from the fact that the same internal representation of data. Example of the data types in Python you can refer to the video lecture

    Setting the Data Type

    In Python, the data type is set when you assign a value to a variable:

    Example                                                             Data Type

    x = "Hello World"                                                    str          

    x = 20                                                                       int          

    x = 20.5                                                                  float         

    x = 1j                                                                  complex       

    x = ["apple", "banana", "cherry"]                            list          

    x = ("apple", "banana", "cherry")                           tuple        

    x = range(6)                                                            range       

    x = {"name" : "John", "age" : 36}                             dict          

    x = {"apple", "banana", "cherry"}                            set           

    x = frozenset({"apple", "banana", "cherry"})    frozenset     

    x = True                                                                      bool          

    x = b"Hello"                                                                bytes          

    x = bytearray(5)                                                   bytearray     

    x = memoryview(bytes(5))                               memoryview




    SUMMARY

    To identify the basic data types for integer, floating, and string and how to declare a variables.

                                                                                     Python Variables and Data Types - A complete guide for beginners - DataFlair


      Duration for the lecture is 1 hour

    View only 'Topic 5'
  • LEARNING OUTCOMES

    By the end of this topic, you will be able to:

    1. Discuss the constants and variables

    2. Show the variable naming, assignment statement and reserved words

     

    6.1 DECLARATION

    In Python, variables are names that can be assigned a value and then used to refer to that value throughout your code.

    Variables are fundamental to programming for two reasons:

    1. Variables keep values accessible: For example, you can assign the result of some time-consuming operation to a variable so that your program doesn’t have to perform the operation each time you need to use the result.

    2. Variables give values context: The number 28 could mean lots of different things, such as the number of students in a class, the number of times a user has accessed a website, and so on. Giving the value 28 a name like num_students makes the meaning of the value clear.

    In this section, you’ll learn how to use variables in your code, as well as some of the conventions Python programmers follow when choosing names for variables.

    Variables can be referring to the containers for storing data values. Python has no command for declaring a variable. A variable is created the moment you first assign a value to it.


    6.2 VARIABLE NAMING AND REGULATIONS

    A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume). Rules for Python variables:

    A variable name must start with a letter or the underscore character

    A variable name cannot start with a number

    A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )

    Variable names are case-sensitive (age, Age and AGE are three different variables)

     

    Legal variable names:

    Example

    myvar = "John"

    my_var = "John"

    _my_var = "John"

    myVar = "John"

    MYVAR = "John"

    myvar2 = "John"


    SUMMARY

    A constant does not change its value over time. A variable, on the other hand, changes its value dependent on the equation. Constants are usually written in numbers. Variables are specially written in letters or symbols. Constants usually represent the known values in an equation, expression or in line of programming.

    Eg:

                                                                                        Constants in C/C++ - GeeksforGeeks 



    Video- Demo 

     

     

    According to the demo, it will be 1 hour and 1 hour practical question will be upload for your next task.

    View only 'Topic 6'
  • LEARNING OUTCOMES 

    By the end of this topics, you will be able to:

    1.  Discuss the arithmetic operations in python

    2. List types of arithmetic operations use

    3. Show the example of arithmetic operations in python

     

    7.1 ADDITION, SUBTRACTION, MULTIPLICATION, DIVISION, MODULUS.

    Operators are used to perform operations on variables and values. In the example below, we use the + operator to add together two values:

    print(10 + 5)


    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     

     

    7.2 OPERATOR PRECEDENCE

    The way we commonly represent expressions, in which operators appear between their operands, is referred to as infix notation. For example, the expression 4 1 3 is in infix notation since the 1 operator appears between its two operands, 4 and 3. There are other ways of representing expressions called prefix and postfix notation, in which operators are placed before and after their operands, respectively.

    The expression 4 1 (3 * 5) is also in infix notation. It contains two operators, 1 and *. The parentheses denote that (3 * 5) is a subexpression. Therefore, 4 and (3 * 5) are the operands of the addition operator, and thus the overall expression evaluates to 19


    7.3 ARITHMETIC EXPRESSION

    An expression is a combination of symbols that evaluates to a value. Expressions, most commonly, consist of a combination of operators and operands,

    4 1 (3 * k)

    An expression can also consist of a single literal or variable. Thus, 4, 3, and k are each expressions. This expression has two subexpressions, 4 and (3 * k). Subexpression (3 * k) itself has two subexpressions, 3 and k.

    Expressions that evaluate to a numeric type are called arithmetic expressions. A sub expres sion is any expression that is part of a larger expression. Subexpressions may be denoted by the use of parentheses, as shown above. Thus, for the expression 4 1 (3 * 2), the two operands of the addition operator are 4 and (3 * 2), and thus the result it equal to 10. If the expression were instead written as (4 1 3) * 2, then it would evaluate to 14.

    Since a subexpression is an expression, any subexpression may contain subexpressions of its own,

    4 1 (3 * (2 2 1)) 4 1 (3 * 1) 4 1 3 7

    If no parentheses are used, then an expression is evaluated according to the rules of operator precedence in Python.


    SUMMARY

    In this topic you have learnt that: to add, multiply, division and modulus. This chapter also introduced you about the example of Operators and arithmetic expression.

    Operator precedence- programming language has its own rules for the order that operators are applied.

    An expression is a combination of symbols that evaluates to a value. Expressions, most commonly, consist of a combination of operators and operands.

    Arithmetic operators are used with numeric values to perform common mathematical operations.                   

                                                                                    Python Tutorials: Arithmetic Operators In Python - DevOpsSchool.com


      
    Regarding the video lecture and SIM note, there are following things we will do today:

    0.5 hour explanation
    0.5 hour QA session
     

    View only 'Topic 7'
  • LEARNING OUTCOMES

    By the end of this topics, you will be able to:

    1. Discuss types of selection constructs in the program

    2. Apply selection construct into the program

     

    8.1 RELATIONAL AND LOGICAL OPERATORS

    Python supports the usual logical conditions from mathematics:

    Equals: a == b

    Not Equals: a != b

    Less than: a < b

    Less than or equal to: a <= b

    Greater than: a > b

    Greater than or equal to: a >= b

    These conditions can be used in several ways, most commonly in "if statements" and loops. An "if statement" is written by using the if keyword.


    SUMMARY

    In this topic you have learnt about selection construct as such if statement, multiple if, nested if and el if.

    Control structure- Control flow is the order that instructions are executed in a program. A control statement is that determines the control flow of a set of instructions. There are three fundamental forms of control that programming languages provide—sequential control, selection control, and iterative control.


                                                                                          Python Tutorials - Selection Statements | Decision Making | Flow Controls

                                                                                                       if.. else statement

                                                                                   The Single-Alternative Decision Structure – Aristides S. Bouras

                                                                                                        single if statement

                                                Are nested 'if-else' allowed in Python? - Quora

                                                                                                       Nested if statement


                                                                         if ... elif ... else Statements in python | GKIndex

                                                                                                              elif statement


    Code Demo:

     

     

    Refer to the above video lecture, you will need 0.5 hour to understand the topic and 0.5 hour to complete brainstorming question. 

    View only 'Topic 8'
  • LEARNING OUTCOMES

    By the end of this topics, you will be able to:

    1. Discuss types of iteration constructs

    2. Apply iteration construct into the program

     

    Iterative Control

    An iterative control statement is a control statement providing the repeated execution of a set of instructions. An iterative control structure is a set of instructions and the iterative control statement(s) controlling their execution. Because of their repeated execution, iterative control structures are commonly referred to as “loops.” We look at one specific iterative control statement next, the while statement.

     

    9.1 WHILE LOOP

    A while statement is an iterative control statement that repeatedly executes a set of statements based on a provided Boolean expression (condition). All iterative control needed in a program can be achieved by use of the while statement. Figure 9 contains an example of a while loop in Python that sums the first n integers, for a given (positive) value n entered by the user. 

    As long as the condition of a while statement is true, the statements within the loop are (re)executed. Once the condition becomes false, the iteration terminates and control continues with the first statement after the while loop. Note that it is possible that the first time a loop is reached, the condition may be false, and therefore the loop would never be executed.


    9.2 FOR LOOP

    A for loop is used for iterating over a sequence (that is a list, a tuple, a dictionary, a set, or a string). This is less like the for keyword in other programming languages, and works more like an iterator method as found in other object-orientated programming languages.

    With the for loop we can execute a set of statements, once for each item in a list, tuple, set etc.


    SUMMARY

    With the while loop we can execute a set of statements as long as a condition is true.

    A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).

    This is less like the for keyword in other programming languages, and works more like an iterator method as found in other object-orientated programming languages.

    With the for loop we can execute a set of statements, once for each item in a list, tuple, set etc.

                                                                        
                                                                                                      While loop

                                                                        
                                                                                                        For loop

    **Video link lecture will upload soon**
    Duration for the video lecture will be 4 hours, 2 hours lecture and the remaining is Q and A session

    View only 'Topic 9'
  • LEARNING OUTCOMES

    After reading this chapter and completing the exercises, you will be able to:

    ♦          Explain what an array is in programming

    ♦          Describe the typical operations performed on array

    ♦          Effectively create and use array in Python

     

    This chapter shows you how to use LISTS as ARRAYS, however, to work with arrays in Python you will have to import a library, like the NumPy library.

     

    10.1 DECLARATIONS OF ARRAYS

    An array is a special variable, which can hold more than one value at a time.

    If you have a list of items (a list of car names, for example), storing the cars in single variables could look like this:

    car1 = "Ford"

    car2 = "Volvo"

    car3 = "BMW"

    However, what if you want to loop through the cars and find a specific one? And what if you had not 3 cars, but 300?

    The solution is an array. An array can hold many values under a single name, and you can access the values by referring to an index number.


    10.2 ACCESS THE ELEMENT OF AN ARRAY

    You refer to an array element by referring to the index number.

    Example

    cars = ["Ford", "Volvo", "BMW"]

    x = cars[0]

    print(x)


    Method             Description

    append()          Adds an element at the end of the list

    clear()               Removes all the elements from the list

    copy()               Returns a copy of the list

    count()              Returns the number of elements with the specified value

    extend()           Add the elements of a list (or any iterable), to the end of the current list

    index()              Returns the index of the first element with the specified value

    insert()              Adds an element at the specified position

    pop()                 Removes the element at the specified position

    remove()          Removes the first item with the specified value

    reverse()           Reverses the order of the list

    sort()                 Sorts the list

    Note: Python does not have built-in support for Arrays, but Python Lists can be used instead.


    SUMMARY

    An array is a collection of items stored at contiguous memory locations. The idea is to store multiple items of the same type together. This makes it easier to calculate the position of each element by simply adding an offset to a base value, i.e., the memory location of the first element of the array (generally denoted by the name of the array).

    Python arrays are used when you need to use many variables which are of the same type. It can also be used to store a collection of data. The arrays are especially useful when you have to process the data dynamically. Python arrays are much faster than list as it uses less memory.

    You can write an array by using following syntax:

                                                              


                                                                               Remove First Element from List in Python | FavTutor

                                                                                                 Remove Arrays Example                                             

     

     

    Refer to the video lecture, you are required to understand single array and 2D array. Time to allocate is 1 hour. You need to present the outcome through zoom application.

    View only 'Topic 10'
  •                                                                                                       

                                                                                

    In Python, we can create simple games very quickly. In this video, we will discuss the implementation of the Python Hangman Game.The hangman game is a multiplayer game. In this game, one player selects a word. Other players have a certain number of guesses to guess the characters in the word. If the players are able to guess the characters in the entire word within certain attempts, they win. Otherwise, they lose.

     

     

    View only 'Topic 11'
  • View only 'Topic 12'
  • View only 'Topic 13'