Sunday, October 7, 2018


1.             WAP to enter age and check if it greater than equal to 18 then print “Eligible to vote” else print  “Not eligible to vote”.

WAP to check whether a number is odd or even.
1.             WAP to check whether a number is Positive or Negative.
  1. WAP to enter year and check whether it is leap year or not.
WAP to enter character and check whether it is a vowel or not

4.             WAP to calculate the commissutiln of a salesman which is 10% if the sale made by the employee is above 10,000.
  1. WAP to calculate the commissutiln of a salesman which is 10% if the sale made by the employee is above 10,000 and 5% if sales is below it.
  2. WAP to find the grade of the students depending upon the marks given as below :
Marks >= 90                                         Grade    ‘A’
Marks >= 80   and  Marks < 90              Grade    ‘B’
Marks >= 70   and  Marks < 80              Grade    ‘C’
Marks >= 60   and  Marks < 70              Grade    ‘D’
Marks < 60                                           Grade    ‘F’
2.             WAP to enter any two numbers and find the greater of the two.
WAP to enter any three numbers and find the greatest of the three.

4.              A library charges a fine for books returned late. Following are the fines.
  First 5 days                :   40 paise per day
  6 to 10 days                :   65 paise per day
  Above 10 days            :   80 paise per day
              WAP to calculate the fine assuming that a book is returned ‘n’ days late.

5.              WAP to compute charges for sending parcels where the charges are as follows:
For the first 1 kg Rs.15.00.For additutilnal weight for every 500gm or fractutiln there of Rs. 8.00.


6.             WAP to calculate the telephone bill amount as per instructutilns.
 For 1st 100 calls – Rs. 100
 For additutilnal 50 calls – Rs. 2 per call
 For calls > 150 – Rs. 2.50 per call


7.             WAP to enter any character and check if it is a character, digit or a special character.



Saturday, May 19, 2018

PYTHON

What is Python?

Python is a popular programming language. It was created in 1991 by Guido van Rossum.
It is used for:
  • web development (server-side),
  • software development,
  • mathematics,
  • system scripting.
Python is a general purpose, dynamic, high level and interpreted programming language. It supports Object Oriented programming approach to develop applications. It is simple and easy to learn and provides lots of high-level data structures.
Python is easy to learn yet powerful and versatile scripting language which makes it attractive for Application Development.
Python's syntax and dynamic typing with its interpreted nature, makes it an ideal language for scripting and rapid application development.
Python supports multiple programming pattern, including object oriented, imperative and functional or procedural programming styles.
Python is not intended to work on special area such as web programming. That is why it is known as multipurpose because it can be used with web, enterprise, 3D CAD etc.
We don't need to use data types to declare variable because it is dynamically typed so we can write a=10 to assign an integer value in an integer variable.
Python makes the development and debugging fast because there is no compilation step included in python development and edit-test-debug cycle is very fast.


What can Python do?

  • Python can be used on a server to create web applications.
  • Python can be used alongside software to create workflows.
  • Python can connect to database systems. It can also read and modify files.
  • Python can be used to handle big data and perform complex mathematics.
  • Python can be used for rapid prototyping, or for production-ready software development.

Why Python?

  • Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc).
  • Python has a simple syntax similar to the English language.
  • Python has syntax that allows developers to write programs with fewer lines than some other programming languages.
  • Python runs on an interpreter system, meaning that code can be executed as soon as it is written. This means that prototyping can be very quick.
  • Python can be treated in a procedural way, an object-orientated way or a functional way.

Python History

  • Python laid its foundation in the late 1980s.
  • The implementation of Python was started in the December 1989 by Guido Van Rossum at CWI in Netherland.
  • In February 1991, van Rossum published the code (labeled version 0.9.0) to alt.sources.
  • In 1994, Python 1.0 was released with new features like: lambda, map, filter, and reduce.
  • Python 2.0 added new features like: list comprehensions, garbage collection system.
  • On December 3, 2008, Python 3.0 (also called "Py3K") was released. It was designed to rectify fundamental flaw of the language.
  • ABC programming language is said to be the predecessor of Python language which was capable of Exception Handling and interfacing with Amoeba Operating System.
  • Python is influenced by following programming languages:
    • ABC language.
    • Modula-3

Python Syntax compared to other programming languages

  • Python was designed to for readability, and has some similarities to the English language with influence from mathematics.
  • Python uses new lines to complete a command, as opposed to other programming languages which often use semicolons or parentheses.
  • Python relies on indentation, using whitespace, to define scope; such as the scope of loops, functions and classes. Other programming languages often use curly-brackets for this purpose.

JSON

What is JSON?

JSON, or JavaScript Object Notation, is a minimal, readable format for structuring data. It is used primarily to transmit data between a server and web application, as an alternative to XML. Squarespace uses JSON to store and organize site content created with the CMS.

Example

Append ?format=json-pretty to the URL of any page on your Squarespace site and you'll be able to view the JSON data for the site.

Keys and Values

The two primary parts that make up JSON are keys and values. Together they make a key/value pair.
  • Key: A key is always a string enclosed in quotation marks.
  • Value: A value can be a string, number, boolean expression, array, or object.
  • Key/Value Pair: A key value pair follows a specific syntax, with the key followed by a colon followed by the value. Key/value pairs are comma separated.


Types of Values

  • Array: An associative array of values.
  • Boolean: True or false.
  • Number: An integer.
  • Object: An associative array of key/value pairs.
  • String: Several plain text characters which usually form a word.
Numbers, booleans and strings are self-evident, so we'll skip over those sections. Arrays and Objects are explained in more depth below.

Saturday, May 12, 2018

JavaScript

JavaScript is an object-based scripting language that is lightweight and cross-platform.
JavaScript is not compiled but translated. The JavaScript Translator (embedded in browser) is responsible to translate the JavaScript code.

JavaScript is used to create interactive websites. It is mainly used for:
  • Client-side validation
  • Dynamic drop-down menus
  • Displaying data and time
  • Displaying popup windows and dialog boxes (like alert dialog box, confirm dialog box and prompt dialog box)
  • Displaying clocks etc.

Javascript example is easy to code. JavaScript provides 3 places to put the JavaScript code: within body tag, within head tag and external JavaScript file.


The script tag specifies that we are using JavaScript.
The text/javascript is the content type that provides information to the browser about the data.
The document.write() function is used to display dynamic content through JavaScript. We will learn about document object in detail later.


3 Places to put JavaScript code

  1. Between the body tag of html
  2. Between the head tag of html
  3. In .js file (external javaScript)

JavaScript variable is simply a name of storage location. There are two types of variables in JavaScript : local variable and global variable.
There are some rules while declaring a JavaScript variable (also known as identifiers).
  1. Name must start with a letter (a to z or A to Z), underscore( _ ), or dollar( $ ) sign.
  2. After first letter we can use digits (0 to 9), for example value1.
  3. JavaScript variables are case sensitive, for example x and X are different variables.

JavaScript global variable is declared outside the function or declared with window object. It can be accessed from any function.


JavaScript provides different data types to hold different types of values. There are two types of data types in JavaScript.
  1. Primitive data type
  2. Non-primitive (reference) data type
JavaScript is a dynamic type language, means you don't need to specify type of the variable because it is dynamically used by JavaScript engine. You need to use var here to specify the data type.


The JavaScript if-else statement is used to execute the code whether condition is true or false. There are three forms of if statement in JavaScript.
  1. If Statement
  2. If else statement
  3. if else if statement

Choose color and Change text Color

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
       var f= $("#b").val();
$("#p").css("color",f);
    });
});

</script>
</head>
<body>
<form>
<input type="color" id="b" />

<p id="p">Hello</p>

<button>Click me</button>
</form>
</body>
</html>

Friday, May 4, 2018

DS Quespaper

  1. Search, insert and delete in an unsorted array
  2. Search, insert and delete in a sorted array
  3. Given an array A[] and a number x, check for pair in A[] with sum as x
  4. Majority Element
  5. Find the Number Occurring Odd Number of Times
  6. Find the Missing Number
  7. Searching in an array where adjacent differ by at most k
  8. Merge an array of size n into another array of size m+n
  9. Searching in an array where adjacent differ by at most k
  10. Maximum Subarray Sum Excluding Certain Elements
  11. Leaders in an array
  12. Find the only repetitive element between 1 to n-1
  13. Sort elements by frequency | Set 1
  14. Count Inversions in an array | Set 1 (Using Merge Sort)
  15. Two elements whose sum is closest to zero
  16. Shortest Un-ordered Subarray
  17. Shortest Un-ordered Subarray
  18. Check for Majority Element in a sorted array
  19. Union and Intersection of two sorted arrays
  20. Ceiling in a sorted array
  21. Find the two repeating elements in a given array
  22. Sort an array of 0s, 1s and 2s
  23. Find the Minimum length Unsorted Subarray, sorting which makes the complete array sorted
  24. Equilibrium index of an array
  25. Count number of occurrences (or frequency) in a sorted array
  26. Find the repeating and the missing | Added 3 new methods
  27. Median in a stream of integers (running integers)
  28. Find a Fixed Point in a given array
  29. Find sub-array with given sum
  30. Find a triplet that sum to a given value
  31. Find the two numbers with odd occurrences in an unsorted array
  32. Find a pair with the given difference
  33. Find four elements that sum to a given value | Set 1 (n^3 solution)
  34. Find four elements that sum to a given value | Set 2 ( O(n^2Logn) Solution)
  35. Median of two sorted arrays of different sizes
  36. Count the number of possible triangles
  37. Find a peak element
  38. Find number of pairs (x, y) in an array such that x^y > y^x
  39. Count all distinct pairs with difference equal to k
  40. Find if there is a sub-array with 0 sum
  41. Given a sorted array and a number x, find the pair in array whose sum is closest to x
  42. Count 1’s in a sorted binary array
  43. Print All Distinct Elements of a given integer array
  44. Construct an array from its pair-sum array
  45. Find common elements in three sorted arrays
  46. Find the first repeating element in an array of integers
  47. Find position of an element in a sorted array of infinite numbers
  48. Check if a given array contains duplicate elements within k distance from each other
  49. Find the element that appears once
  50. Find Union and Intersection of two unsorted arrays
  51. Delete an element from array (Using two traversals and one traversal)
  52. Count frequencies of all elements in array in O(1) extra space and O(n) time
  53. Trapping Rain Water
  54. Count triplets with sum smaller than a given value
  55. Count Inversions of size three in a given array
  56. Merge two sorted arrays with O(1) extra space
  57. Find lost element from a duplicated array
  58. Count pairs with given sum

  1. Search, insert and delete in an unsorted array
  2. Search, insert and delete in a sorted array
  3. Given an array A[] and a number x, check for pair in A[] with sum as x
  4. Majority Element
  5. Find the Number Occurring Odd Number of Times
  6. Find the Missing Number
  7. Searching in an array where adjacent differ by at most k
  8. Merge an array of size n into another array of size m+n
  9. Searching in an array where adjacent differ by at most k
  10. Maximum Subarray Sum Excluding Certain Elements
  11. Leaders in an array
  12. Find the only repetitive element between 1 to n-1
  13. Sort elements by frequency | Set 1
  14. Count Inversions in an array | Set 1 (Using Merge Sort)
  15. Two elements whose sum is closest to zero
  16. Shortest Un-ordered Subarray
  17. Shortest Un-ordered Subarray
  18. Check for Majority Element in a sorted array
  19. Union and Intersection of two sorted arrays
  20. Ceiling in a sorted array
  21. Find the two repeating elements in a given array
  22. Sort an array of 0s, 1s and 2s
  23. Find the Minimum length Unsorted Subarray, sorting which makes the complete array sorted
  24. Equilibrium index of an array
  25. Count number of occurrences (or frequency) in a sorted array
  26. Find the repeating and the missing | Added 3 new methods
  27. Median in a stream of integers (running integers)
  28. Find a Fixed Point in a given array
  29. Find sub-array with given sum
  30. Find a triplet that sum to a given value
  31. Find the two numbers with odd occurrences in an unsorted array
  32. Find a pair with the given difference
  33. Find four elements that sum to a given value | Set 1 (n^3 solution)
  34. Find four elements that sum to a given value | Set 2 ( O(n^2Logn) Solution)
  35. Median of two sorted arrays of different sizes
  36. Count the number of possible triangles
  37. Find a peak element
  38. Find number of pairs (x, y) in an array such that x^y > y^x
  39. Count all distinct pairs with difference equal to k
  40. Find if there is a sub-array with 0 sum
  41. Given a sorted array and a number x, find the pair in array whose sum is closest to x
  42. Count 1’s in a sorted binary array
  43. Print All Distinct Elements of a given integer array
  44. Construct an array from its pair-sum array
  45. Find common elements in three sorted arrays
  46. Find the first repeating element in an array of integers
  47. Find position of an element in a sorted array of infinite numbers
  48. Check if a given array contains duplicate elements within k distance from each other
  49. Find the element that appears once
  50. Find Union and Intersection of two unsorted arrays
  51. Delete an element from array (Using two traversals and one traversal)
  52. Count frequencies of all elements in array in O(1) extra space and O(n) time
  53. Trapping Rain Water
  54. Count triplets with sum smaller than a given value
  55. Count Inversions of size three in a given array
  56. Merge two sorted arrays with O(1) extra space
  57. Find lost element from a duplicated array
  58. Count pairs with given sum

Tuesday, February 13, 2018

python

Python Moudule

Modules are used to categorize code in Python into smaller part. A module is simply a file, where classes, functions and variables are defined. Grouping similar code into a single file makes it easy to access.
Have a look over example:
If the content of a book is not indexed or categorized into individual chapters, then the book might have turned boring and hectic. Hence, dividing book into chapters made it easy to understand.
In the same sense python modules are the files which have similar code. Thus module is simplify a python code where classes, variables and functions are defined.
Advantage:
Python provides the following advantages for using module:
1) Reusability: Module can be used in some other python code. Hence it provides the facility of code reusability.
2) Categorization: Similar type of attributes can be placed in one module.

Importing a Module:

There are different ways by which you we can import a module. These are as follows:

1) Using import statement:

"import" statement can be used to import a module.
Syntax:
  1. import <file_name1, file_name2,...file_name(n)="">  
  2. </file_name1,>  
Have a look over an example:
eg:
  1. def add(a,b):  
  2.     c=a+b  
  3.     print c  
  4.     return  
Save the file by the name addition.py. To import this file "import" statement is used.
  1. import addition  
  2. addition.add(10,20)  
  3. addition.add(30,40)

Sunday, January 7, 2018

python

Date and Time

Python is very useful in case of Date and Time. We can easily retrieve current date and time using Python.

Retrieve Time

To retrieve current time a predefined function localtime() is used. localtime() receives a parameter time.time() . Here,
time is a module,
time() is a function that returns the current system time in number of ticks since 12:00 am , January 1,1970. It is known as epoch.
Tick is simply a floating point number in seconds since epoch.

  1. import time;  
  2. localtime = time.localtime(time.time())  
  3. print "Current Time is :", localtime




  1. import calendar  
  2. calendar.prcal(2017)  

  1. import calendar  
  2. print (calendar.isleap(2000))

  1. import calendar  
  2. print (calendar.monthcalendar(2014,6))


  1. import calendar  
  2. print (calendar.prmonth(2014,6) )


  1. import calendar  
  2. print "Current month is:"  
  3. cal = calendar.month(20146)  
  4. print (cal)  


  1. import time  
  2. t = (2014626173381480)  
  3. t = time.mktime(t)  
  4. print (time.strftime("%b %d %Y %H:%M:%S", time.gmtime(t)))