Tuesday, 5 November 2019


                                          FUNDAMENTALS OF COMPUTER SCIENCE 
SYLLABUS

UNIT I:
A Simple Computer System: Central processing unit, the further need of secondary storage, Types of memory, Hardware, Software and people.
Peripheral Devices: Input, Output and storage, Data Preparation, Factors affecting input, Input devices, Output devices, Secondary devices, Communication between the CPU and Input/ Output devices. (Text Book 1)
UNIT II:
Problem Solving and Programming: Algorithm development, Flowcharts, Looping, some programming features, Pseudo code, the one-zero game, some structured programming concepts, documents.
Programming Languages: Machine Language and assembly language, high -level and low level languages, Assemblers, Compilers, and Interpreters (Text Book 1)
UNIT III:
Computer Networks : Introduction to computer Networks, Network topologies-Bus topology, star topology, Ring topology, Mesh topology, Hybrid topology, Types of Networks: Local area Network, Wide Area Networks, Metropolitan Networks, Campus/ Corporate Area Network, Personal Area Network, Network Devices- Hub, Repeater, Switch, Bridge, Router, Gateway, Network interface Card, Open System Inter connection Model (Text Book 2)
Operating systems: Introduction, Evolution of operating systems, Process Management- Process control block, Process operations, Process scheduling, Command Interpreter, Popular operating systems- Microsoft DOS, Microsoft Windows, UNIX and Linux. (Text Book 2)
UNIT IV:
Database Systems: File-Oriented Approach, Database-oriented Approach-Components of Database system, Advantages & Disadvantages of Database approach, Applications of Database systems, Database views, Three-schema architecture, Database models-Hierarchical model, Network Model, relational Model, Object-oriented Data Model, Components of database management systems, Retrieving Data through Queries (Text Book 2)
Computer Systems and Development: Investigation, Analysis, Design, system processing and general program design, Presentation to management and users, Implementation, Documents. (Text Book 1)
UNIT V:
Emerging Computer Technologies: Distributed Networking, Peer-to-peer Computing, Categorization of Peer-to-peer system Applications of Peer-to-peer networks, Grid Computing-components of Grid computing, Applications of Grid computing,, Cloud Computing-characteristics of cloud computing systems, cloud computing services, cloud computing architecture, cloud computing applications, Cloud computing concerns
Wireless Networks: Wireless network operations, Types of wireless networks, security in wireless Networks, Limitations of wireless Networks, Bluetooth – Bluetooth Piconets, Avoiding Interference in Bluetooth Devices, Bluetooth Security, Differences between Bluetooth and Wireless Networks. (Text Book 2)
TEXT BOOKS:
1. An Introduction to Computer studies –Noel Kalicharan-Cambridge
2. Fundamentals of Computers –Reema Thareja-Oxford higher education
REFERENCES:
1. Introduction to Information Technology – ITL education Solution Limited, Pearson
2. Computer Science and overview-J. Glenn Brookshear, Dennis Brylow-Pearson

Thursday, 8 August 2019

python functions

What is a Function in Python?

A Functions in Python are used to utilize the code in more than one place in a program, sometimes also called method or procedures. Python provides you many inbuilt functions like print(), but it also gives freedom to create your own functions.
In this tutorial, we will learn

How to define and call a function in Python

Function in Python is defined by the "def " statement followed by the function name and parentheses ( () )
Example:
Let us define a function by using the command " def func1():" and call the function. The output of the function will be "I am learning Python function".
Python Functions Tutorial - Define, Call, Indentation & Arguments
The function print func1() calls our def func1(): and print the command " I am learning Python function None."
There are set of rules in Python to define a function.
  • Any args or input parameters should be placed within these parentheses
  • The function first statement can be an optional statement- docstring or the documentation string of the function
  • The code within every function starts with a colon (:) and should be indented (space)
  • The statement return (expression) exits a function, optionally passing back a value to the caller. A return statement with no args is the same as return None.

Significance of Indentation (Space) in Python

Before we get familiarize with Python functions, it is important that we understand the indentation rule to declare Python functions and these rules are applicable to other elements of Python as well like declaring conditions, loops or variable.
Python follows a particular style of indentation to define the code, since Python functions don't have any explicit begin or end like curly braces to indicate the start and stop for the function, they have to rely on this indentation. Here we take a simple example with "print" command. When we write "print" function right below the def func 1 (): It will show an "indentation error: expected an indented block".
Python Functions Tutorial - Define, Call, Indentation & Arguments
Now, when you add the indent (space) in front of "print" function, it should print as expected.
Python Functions Tutorial - Define, Call, Indentation & Arguments
At least, one indent is enough to make your code work successfully. But as a best practice it is advisable to leave about 3-4 indent to call your function.
It is also necessary that while declaring indentation, you have to maintain the same indent for the rest of your code. For example, in below screen shot when we call another statement "still in func1" and when it is not declared right below the first print statement it will show an indentation error "unindent does not match any other indentation level."
Python Functions Tutorial - Define, Call, Indentation & Arguments
Now, when we apply same indentation for both the statements and align them in the same line, it gives the expected output.
Python Functions Tutorial - Define, Call, Indentation & Arguments

How Function Return Value?

Return command in Python specifies what value to give back to the caller of the function.
Let's understand this with the following example
Step 1) Here - we see when function is not "return". For example, we want the square of 4, and it should give answer "16" when the code is executed. Which it gives when we simply use "print x*x" code, but when you call function "print square" it gives "None" as an output. This is because when you call the function, recursion does not happen and fall off the end of the function. Python returns "None" for failing off the end of the function.
Python Functions Tutorial - Define, Call, Indentation & Arguments
Step 2) To make this clearer we replace the print command with assignment command. Let's check the output.
Python Functions Tutorial - Define, Call, Indentation & Arguments
When you run the command "print square (4)" it actually returns the value of the object since we don't have any specific function to run over here it returns "None".
Step 3) Now, here we will see how to retrieve the output using "return" command. When you use the "return" function and execute the code, it will give the output "16."
Python Functions Tutorial - Define, Call, Indentation & Arguments
Step 4) Functions in Python are themselves an object, and an object has some value. We will here see how Python treats an object. When you run the command "print square" it returns the value of the object. Since we have not passed any argument, we don't have any specific function to run over here it returns a default value (0x021B2D30) which is the location of the object. In practical Python program, you probably won't ever need to do this.
Python Functions Tutorial - Define, Call, Indentation & Arguments

Arguments in Functions

The argument is a value that is passed to the function when it's called.
In other words on the calling side, it is an argument and on the function side it is a parameter.
Let see how Python Args works -
Step 1) Arguments are declared in the function definition. While calling the function, you can pass the values for that args as shown below
Python Functions Tutorial - Define, Call, Indentation & Arguments
Step 2) To declare a default value of an argument, assign it a value at function definition.
Python Functions Tutorial - Define, Call, Indentation & Arguments
Example: x has no default values. Default values of y=0. When we supply only one argument while calling multiply function, Python assigns the supplied value to x while keeping the value of y=0. Hence the multiply of x*y=0
Python Functions Tutorial - Define, Call, Indentation & Arguments
Step 3) This time we will change the value to y=2 instead of the default value y=0, and it will return the output as (4x2)=8.
Python Functions Tutorial - Define, Call, Indentation & Arguments
Step 4) You can also change the order in which the arguments can be passed in Python. Here we have reversed the order of the value x and y to x=4 and y=2.
Python Functions Tutorial - Define, Call, Indentation & Arguments
Step 5) Multiple Arguments can also be passed as an array. Here in the example we call the multiple args (1,2,3,4,5) by calling the (*args) function.
Example: We declared multiple args as number (1,2,3,4,5) when we call the (*args) function; it prints out the output as (1,2,3,4,5)
Python Functions Tutorial - Define, Call, Indentation & Arguments
Tips:
  • In Python 2.7. function overloading is not supported in Python. Function Overloading is the ability to create multiple methods of the same name with a different implementation. Function Overloading is fully supported in Python 3
  • There is quite a confusion between methods and functions. Methods in Python are associated with object instances while function are not. When Python calls a method, it binds the first parameter of that call to the appropriate object reference. In simple words, a standalone function in Python is a "function", whereas a function that is an attribute of a class or an instance is a "method".

Here is the complete Python 3 code

#define a function
def func1():
   print ("I am learning Python function")
   print ("still in func1")
   
func1()

def square(x):
   return x*x
print(square(4))

def multiply(x,y=0):
 print("value of x=",x)
 print("value of y=",y)
    
 return x*y
  
print(multiply(y=2,x=4))

Here is the complete Python 2 code

#define a function
def func1():
   print " I am learning Python function"
   print " still in func1"
   
func1()

def square(x):
   return x*x
print square(4)

def multiply(x,y=0):
 print"value of x=",x
 print"value of y=",y
    
 return x*y
  
print multiply(y=2,x=4)

Summary:

Function in Python is a piece of reusable code that is used to perform single, related action. In this article, we will see
  • Function defined by the def statement
  • The code block within every function starts with a colon (:) and should be indented (space)
  • Any arguments or input parameters should be placed within these parentheses, etc.
  • At least one indent should be left before the code after declaring function
  • Same indent style should be maintained throughout the code within def function
  • For best practices three or four indents are considered best before the statement
  • You can use the "return" command to return values to the function call.
  • Python will print a random value like (0x021B2D30) when the argument is not supplied to the calling function. Example "print function."
  • On the calling side, it is an argument and on the function side it is a parameter
  • Default value in argument - When we supply only one argument while calling multiply function or any other function, Python assigns the other argument by default
  • Python enables you to reverse the order of the argument as wel

Sunday, 28 July 2019

python numpy

What is a Python NumPy?

NumPy is a Python package which stands for ‘Numerical Python’. It is the core library for scientific computing, which contains a powerful n-dimensional array object, provide tools for integrating C, C++ etc. It is also useful in linear algebra, random number capability etc. NumPy array can also be used as an efficient multi-dimensional container for generic data. Now, let me tell you what exactly is a python numpy array.
NumPy Array: Numpy array is a powerful N-dimensional array object which is in the form of rows and columns. We can initialize numpy arrays from nested Python lists and access it elements. In order to perform these numpy operations, the next question which will come in your mind is:

How do I install NumPy?

To install Python NumPy, go to your command prompt and type “pip install numpy”.

Here, I have different elements that are stored in their respective memory locations. It is said to be two dimensional because it has rows as well as columns. In the above image, we have 3 columns and 4 rows available.
Let us see how it is implemented in PyCharm:

Single-dimensional Numpy Array:

1
2
3
from numpy import *
a=array([1,2,3])
print(a)
Output – [1 2 3]

Multi-dimensional Array:

1
2
a=array([(1,2,3),(4,5,6)])
print(a)
O/P – [[ 1 2 3]
[4 5 6]]

Many of you must be wondering that why do we use python numpy if we already have python list? So, let us understand with some examples in this python numpy tutorial.

Python NumPy Array v/s List

We use python numpy array instead of a list because of the below three reasons:
  1. Less Memory
  2. Fast
  3. Convenient
The very first reason to choose python numpy array is that it occupies less memory as compared to list. Then, it is pretty fast in terms of execution and at the same time it is very convenient to work with numpy. So these are the major advantages that python numpy array has over list.

Python NumPy Operations

  • NumpyArray - python numpy tutorial - Edurekandim:
    You can find the dimension of the array, whether it is a two-dimensional array or a single dimensional array. So, let us see this practically how we can find the dimensions. In the below code, with the help of ‘ndim’ function, I can find whether the array is of single dimension or multi dimension.
1
2
3
from numpy import *
a = array([(1,2,3),(4,5,6)])
print(a.ndim)
Output – 2
Since the output is 2, it is a two-dimensional array (multi dimension).
  • NumpyByte - python numpy tutorial - Edurekaitemsize:
    You can calculate the byte size of each element. In the below code, I have defined a single dimensional array and with the help of ‘itemsize’ function, we can find the size of each element.
    1
    2
    3
    from numpy import *
    a = array([(1,2,3)])
    print(a.itemsize)
    Output – 4
    So every element occupies 4 byte in the above numpy array.
  • dtype:
    You can find the data type of the elements that are stored in an array. So, if you want to know the data type of a particular element, you can use ‘dtype’ function which will print the datatype along with the size. In the below code, I have defined an array where I have used the same function.
1
2
3
from numpy import *
a = array([(1,2,3)])
print(a.dtype)
Output – int32
As you can see, the data type of the array is integer 32 bits. Similarly, you can find the size and shape of the array using ‘size’ and ‘shape’ function respectively.

Output – 6 (1,6)
Next, let us move forward and see what are the other operations that you can perform with python numpy module. We can also perform reshape as well as slicing operation using python numpy operation. But, what exactly is reshape and slicing? So let me explain this one by one in this python numpy tutorial.
  • reshape:
    Reshape is when you change the number of rows and columns which gives a new view to an object. Now, let us take an example to reshape the below array:
    NumpyArrayReshape - python numpy tutorial - Edureka 
    As you can see in the above image, we have 3 columns and 2 rows which has converted into 2 columns and 3 rows. Let me show you practically how it’s done.
    1
    2
    3
    4
    5
    from numpy import *
    a = array([(8,9,10),(11,12,13)])
    print(a)
    a=a.reshape(3,2)
    print(a)
    Output – [[ 8 9 10] [11 12 13]] [[ 8 9] [10 11] [12 13]]
  • slicing:
    As you can see the ‘reshape’ function has showed its magic. Now, let’s take another operation i.e Slicing. Slicing is basically extracting particular set of elements from an array. This slicing operation is pretty much similar to the one which is there in the list as well. Consider the following example:
    NumpyArraySlicing - python numpy tutorial - Edureka
    Before getting into the above example, let’s see a simple one. We have an array and we need a particular element (say 3) out of a given array. Let’s consider the below example:
    1
    2
    3
    import numpy as np
    a=np.array([(1,2,3,4),(3,4,5,6)])
    print(a[0,2])
    Output – 3
    Here, the array(1,2,3,4) is your index 0 and (3,4,5,6) is index 1 of the python numpy array. Therefore, we have printed the second element from the zeroth index.
    Taking one step forward, let’s say we need the 2nd element from the zeroth and first index of the array. Let’s see how you can perform this operation:
    1
    2
    3
    import numpy as np
    a=np.array([(1,2,3,4),(3,4,5,6)])
    print(a[0:,2])
    Output – [3 5]
    Here colon represents all the rows, including zero. Now to get the 2nd element, we’ll call index 2 from both of the rows which gives us the value 3 and 5 respectively.
    Next, just to remove the confusion, let’s say we have one more row and we don’t want to get its 2nd element printed just as the image above. What we can do in such case?
    Consider the below code:
    1
    2
    3
    import numpy as np
    a=np.array([(8,9),(10,11),(12,13)])
    print(a[0:2,1])
    Output – [9 11]
    As you can see in the above code, only 9 and 11 gets printed. Now when I have written 0:2, this does not include the second index of the third row of an array. Therefore, only 9 and 11 gets printed else you will get all the elements i.e [9 11 13].
  • linspace
    This is another operation in python numpy which returns evenly spaced numbers over a specified interval. Consider the below example:
    1
    2
    3
    import numpy as np
    a=np.linspace(1,3,10)
    print(a)
    Output – [ 1. 1.22222222 1.44444444 1.66666667 1.88888889 2.11111111 2.33333333 2.55555556 2.77777778 3. ]
    As you can see in the result, it has printed 10 values between 1 to 3.
  • max/ min
    Next, we have some more operations in numpy such as to find the minimum, maximum as well the sum of the numpy array. Let’s go ahead in python numpy tutorial and execute it practically.
    1
    2
    3
    4
    5
    6
    import numpy as np
    a= np.array([1,2,3])
    print(a.min())
    print(a.max())
    print(a.sum())
    Output – 1 3 6
    You must be finding these pretty basic, but with the help of this knowledge you can perform a lot bigger tasks as well. Now, lets understand the concept of axis in python numpy.
    NumpyArray - numpy tutorial - Edureka


    As you can see in the figure, we have a numpy array 2*3. Here the rows are called as axis 1 and the columns are called as axis 0. Now you must be wondering what is the use of these axis?
    Suppose you want to calculate the sum of all the columns, then you can make use of axis. Let me show you practically, how you can implement axis in your PyCharm:
    1
    2
    a= np.array([(1,2,3),(3,4,5)])
    print(a.sum(axis=0))
    Output – [4 6 8]
    Therefore, the sum of all the columns are added where 1+3=4, 2+4=6 and 3+5=8. Similarly, if you replace the axis by 1, then it will print [6 12] where all the rows get added.
  • Square Root & Standard Deviation
    There are various mathematical functions that can be performed using python numpy. You can find the square root, standard deviation of the array. So, let’s implement these operations:
    1
    2
    3
    4
    import numpy as np
    a=np.array([(1,2,3),(3,4,5,)])
    print(np.sqrt(a))
    print(np.std(a))
    Output – [[ 1. 1.41421356 1.73205081]
    [ 1.73205081 2. 2.23606798]]
    1.29099444874

    As you can see the output above, the square root of all the elements are printed. Also, the standard deviation is printed for the above array i.e how much each element varies from the mean value of the python numpy array.
  • Addition Operation

    You can perform more operations on numpy array i.e addition, subtraction,multiplication and division of the two matrices. Let me go ahead in python numpy tutorial, and show it to you practically: 
    1
    2
    3
    4
    import numpy as np
    x= np.array([(1,2,3),(3,4,5)])
    y= np.array([(1,2,3),(3,4,5)])
    print(x+y)
    Output – [[ 2 4 6] [ 6 8 10]]
    This is extremely simple! Right? Similarly, we can perform other operations such as subtraction, multiplication and division. Consider the below example:
    1
    2
    3
    4
    5
    6
    import numpy as np
    x= np.array([(1,2,3),(3,4,5)])
    y= np.array([(1,2,3),(3,4,5)])
    print(x-y)
    print(x*y)
    print(x/y)
    Output – [[0 0 0] [0 0 0]]
    [[ 1 4 9] [ 9 16 25]]
    [[ 1. 1. 1.] [ 1. 1. 1.]]
  • Vertical & Horizontal Stacking
    Next, if you want to concatenate two arrays and not just add them, you can perform it using two ways – vertical stacking and horizontal stacking. Let me show it one by one in this python numpy tutorial.
    1
    2
    3
    4
    5
    import numpy as np
    x= np.array([(1,2,3),(3,4,5)])
    y= np.array([(1,2,3),(3,4,5)])
    print(np.vstack((x,y)))
    print(np.hstack((x,y)))
    Output – [[1 2 3] [3 4 5] [1 2 3] [3 4 5]]
    [[1 2 3 1 2 3] [3 4 5 3 4 5]]





 


Thursday, 25 July 2019

python tutorial

python hands on exercises


Hands on Exercises
Basic Programs:
3.      Python program to display calendar of given month of the year

Array Programs:
   7.    Write a python program to read a number and print a matrix of n*n size in spiral order with row sums and column sum and diagonal elements sum?
Hint: n=4 then print 4*4 matrix should be like
List Programs:

String Programs:
2.      Print the substring “WELCOME” from the given string “WELCOME TO PYTHON LANGUAGE”


Tuple Programs:

Dictionary Programs:

Sets programs

File Handling Programs:

7.      Write a python program to create a file with roll no, name, year, sem and 6 subject marks and write them in a file and then calculate the total, percentage of each student and also find the rank of each student in the file?

  QR code for automation