Posts

Showing posts from August, 2020

C program to find power of given number.

Question: Write a Program in C to find out value of given power(X,Y) of number using recursion. Source Code: #include void Pow1(int x,int y) { if(y==0) { printf("1"); } else { printf(x*Pow1(x,(y-1))); } } int main() { int x,y; printf("Enter the value of x and y\n"); scanf("%d \n %d \n",&x,&y); printf("Value is:\n"); Pow1(x,y); return 0; } Output: Enter the value of x and y 2 2 Value is: 4

C program to find roots of Quadratic Equation.

Question: Write a Program in C to find the roots of Quadratic Equation. Source Code: #include #include int main() { int a,b,c,det; double root1,root2; printf("Enter the value of a, b and c from Quadratic Equation\n"); scanf("%f \n %f \n %f \n" ,&a, &b, &c); det=(b*b)-(4*a*c); if(det Output: Enter the value of a, b and c from Quadratic Equation 1 -2 1 Root1=1.00 Root2=1.00

C program to find fibonacci series.|c |languagecopy.blogspot.

Question: Write a Program in C to take input from user and find the fibonacci series of number. Source Code: #include void fib(int num1) { if(num1==0) { printf("0"); } else if(num1==1) { printf("0 , 1"); } else { int term1=0,term2=1; int i,next; for(i=0;i Output: Enter the number to find the fibonacci series 5 fibonacci series: 0,1,1,2,3,

C program to take elements of Matrix 3x3 and find transpose of matrix.|C |languagecopy.blogspot.com|

Question: Write a Program in C to take elements of a matrix[3][3] and find the transpose of matrix. Source Code: #include int main() { int mat[3][3],i,j; printf("Enter the elements of matrix 3X3\n"); for(i=0;i Output: Enter the elements of matrix 3X3 Original Mtrix is: 1 2 3 4 5 6 7 8 9 Transpose of Mtrix is: 1 4 7 2 5 8 3 6 9

C program to find the factorial of number.|Recursion Function|

Question: Write a Program in C to take input from user and find the factorial of a given number. Source Code: #include int fact(int num) { if (num==0 || num==1) { return 1; } else { return (num*fact(num-1)); } } int main() { int num1; printf("Enter Number\n"); scanf("%d",&num1); printf("Factorial of numbers is :%d",fact(num1)); return 0; } Output: Enter Number 5 Factorial of numbers is:120

C program to create a simple Calculator using Function.

Question: Write a Program in C to create a simple calculator to perform addition, subtraction, multiplication division and modulus. Source Code: #include int add(int a, int b) { return a+b; } int sub(int a, int b) { return a-b; } int mul(int a, int b) { return a*b; } int divi(int a, int b) { return (a/b); } int mod(int a, int b) { return a%b; } int main() { int num1,num2,choice; char c; hello: printf("*Calculator*\n"); printf("Enter Choice\n"); printf("1. Addition \n 2. Subtraction \n 3. Multiplication \n 4. Division \n 5. Modulus \n "); scanf("%d",&choice); switch(choice) { case 1: printf("Enter two numbers;\n"); scanf("%d \n %d",&num1,&num2); printf("Addition:%d",add(num1,num2)); break; case 2: printf("Enter two numbers;\n"); scanf("%d \n %d",&num1,...

C program to subtract Matrix1 to Mtrix2.

Question: Write a C program to take elements of two matrix 3 X 3 and do the subtraction and display the result. Source Code: #include int main() { int mat1[3][3],i,j; int mat2[3][3],mat3[3][3]; printf("Enter elements of Matrix 1\n"); for(i=0;i Output: Enter elements of Matrix 1 1 2 3 4 5 6 7 8 9 Enter elements of Matrix 2 1 2 4 5 6 7 8 9 elements of Matrix 1 1 2 3 4 5 6 7 8 9 elements of Matrix 2 1 2 3 4 5 6 7 8 9 Subtraction of two matrix is: 0 0 0 0 0 0 0 0 0

C program to addition of two matrix.

Question: Write a C program to take elements of two matrix 3 X 3 and add both matrix. Source Code: #include int main() { int mat1[3][3],i,j; int mat2[3][3],mat3[3][3]; printf("Enter elements of Matrix 1\n"); for(i=0;i Output: Enter elements of Matrix 1 1 2 3 4 5 6 7 8 9 Enter elements of Matrix 2 1 2 4 5 6 7 8 9 elements of Matrix 1 1 2 3 4 5 6 7 8 9 elements of Matrix 2 1 2 3 4 5 6 7 8 9 Addition of two matrix is: 2 4 6 8 10 12 14 16 18

C program to swap elements of two Array.

Question: Write a C program to take two array of 5-5 elements and swap elements of Array A to Array B. Source Code: #include int main() { int arrA[5],arrB[5],i,temp; printf("Enter elements of Array A\n"); for(i=0;i Output: Enter elements of Array A 2 3 4 5 6 Enter elements of Array B 7 8 9 10 11 After Swapping arrayA arrayB 7 2 8 3 9 4 10 5 11 6

C program to find all even numbers from an Array.

Question: Write a C program to take 5 numbers from user and display all even numbers from them. Source Code: #include int main() { int arr[5],i; printf("Enter 5 numbers\n"); for(i=0;i Output: Enter 5 numbers 34 23 45 56 34 Even Numbers are: 34 56 34

C program to reverse the given number.|Without function | Using Function|

Question: Write a programm in C to reverse the given number. Source Code: #include int main() { int num,sum=0,rem; printf("Enter num \n"); scanf("%d",&num); while(num !=0) { rem=num%10; sum=(sum*10)+rem; num=num/10; } printf("Reverse of number: %d\n",sum); return 0; } Output: Enter num 345 Reverse of number: 543 Using Function: #include void reverse(int num) { int sum=0,rem; while(num !=0) { rem=num%10; sum=(sum*10)+rem; num=num/10; } printf("Reverse of number: %d\n",sum); } int main() { int num1; printf("Enter num1 \n"); scanf("%d",&num1); reverse(num1); return 0; } Output: Enter num 789 Reverse of number: 987

C program to find sum of square of digit.|without function| with Function.

Question: Write a programm in C to find sum of square of digit of the number. Source Code: #include int main() { int num1,sum=0,rem; printf("Enter num1 \n"); scanf("%d",&num1); while(num1 !=0) { rem=num1%10; sum=sum+(rem*rem); num1=num1/10; } printf("Sum of square of digit: %d\n",sum); return 0; } Output: Enter num1 23 Sum of square of digit: 13 Using Function: #include void squareDigit(int num) { int sum=0,rem; while(num !=0) { rem=num%10; sum=sum+(rem*rem); num=num/10; } printf("Sum of square of digit: %d\n",sum); } int main() { int num1; printf("Enter num1 \n"); scanf("%d",&num1); squareDigit(num1); return 0; } Output: Enter num1 13 Sum of square of digit: 10

Write a C program to swapping of two numbers with and without third variable.

Source Code: without third variable. #include int main() { int num1,num2; printf("Enter num1 \n"); scanf("%d",&num1); printf("Enter num2 \n"); scanf("%d",&num2); printf("Number before swapping:\n"); printf("num1:%d\n",num1); printf("num2:%d\n",num2); num1=num1+num2; num2=num1-num2; num1=num1-num2; printf("Number after swapping:\n"); printf("num1:%d\n",num1); printf("num2:%d\n",num2); return 0; } Output: Enter num1 67 Enter num2 45 Number before swapping: num1:67 num2:45 Number after swapping: num1:45 num2:67 With third variable: #include int main() { int num1,num2,num3; printf("Enter num1 \n"); scanf("%d",&num1); printf("Enter num2 \n"); scanf("%d",&num2); printf("Number before swapping:\n"); printf("num1:%d\n",num1); ...

Write C program to sort the given numbers in ascending orders.

Ascending order: Ascending order means the elements will be sorted in increasing order. Source Code: #include void main() { int num[5],i,j,temp; printf("Enter 5 numbers:\n"); for(i=0;i num[j]) { temp=num[i]; num[i]=num[j]; num[j]=temp; } } } printf("soted elements are:\n"); for(i=0;i Output: Enter 5 numbers: 34 67 45 87 90 soted elements are: 34 45 67 87 90

Functions in Python.

Python Functions: In python, function is a group of related statements that perform a specific task. A function is a block of organized, reusable cod that is used to perform a single, related action. Functions provide better modularity for your application and a high degree of code reusing. Types of Functions: i)Built in Functions ii) User defined Functions Built in Functions: You already know, Python gives you many built in functions like print(). User defined Function You can also create your own functions. These functions are called user defined function. Example: def swap(x,y): '''creating user temp=x define swap x=y function''' y=temp return x,y x=2 y=3 print(swap(x,y)) #calling function Outupt: (3,2) Defining a Function: Function Definition provides the information about function name, parameters and the definition what operation is to be performed. 'def...

Comments in Python.

Python Comments: A comment in python starts with the hash character(#). Comments are in the source code for humans to read, not for computers to execute. Example: #This is a comment Types of Python comments: 1)Single lined comment 2)Multi lined comment 3)Inline comments Single lined comment: In case user want to specify a single line comment,then comment must start with #. Example: int a=10 #here a is a variable. print("Hello,world") print(a) Output: Hello,world 10 Multi lined comments: Multi lined comment can be given inside triple quotes. Example: ''' This is multiline comment in python''' Inline comments: If a comment is placed on the same line as a statements,it is called an inline comments. Similar to the block comments, an inline comments beigns with a single hash(#) sign and followed by a space and comment. Example: N=10 n+=1 # increase n by 1

Operators in Python.

Operator: Operators are special symbol in python that carry out arithmatic or logical computation, Used to perform specific operation. For Example: >>>2+3 5 Types of Operator: 1. Arithmatic operator 2. Assignment operator 3. Comparison operator 4. Logical operator 5. Bitwise operator 6. Identity operator 7. Membership operator Arithmatic operator: Arithmatic operators are used to perform mathematical operation like addition,subtraction ,multiplication etc. Addition(+): Adds value on either of the operators. Example: a=10 b=20 print(a+b) Output: 30 Subtraction(-): Subtracts right hand operands form left hand oprand. Example: a=20 b=10 print(a-b) Output: 10 Multiplication(*): Multiply values on either side of the operators. Example: a=20 b=10 print(a*b) Output: 200 Division(/): divides left hand operand by right hand operand. Example: a=20 b=10 print(a/b) Output: 2 Module(%): Divides left hand operan...

C program to addition of square of n numbers.

Image
Question: Write C program to find out:   Source Code: #include void main() { int num,iter,sum=0; printf("Enter value of n:\n"); scanf("%d",&num); for(iter=1;iter Output: Enter value of n: 6 Sum of series is:91

Literals in Python.

Literls:- Literal is a raw data given in a variable or consatant. In python, there are various type of literls. Type of Literls:- 1. String 2. Numeric 3. Boolean 4. Special String: String is an immutable data type. String formed by enclosing a text in the qutoes. Both single and double quotes can be used. Example: string='This is python' char="C" print(string) print(char) Output: This is python C Numeric Literls: Numeric literals are immutable data type. Numeric literals can belong to four different Numeric type. Types of Numeric Literls: .Integer .Long .Float .Complex integer(signed integer): Number( can be +ve and -ve) with nuber fractional part. Example: 230 Long(long integer): Integer of unlimited size followed by lower case or uppercase. Example 8703285L Float(folating point): Real numer with both integer and fractional part. Example 35.2 Complex(complex): In the form ...

C program to calculate average of marks and display grade.

Question: Write a C program to take marks of 5 subjects from user and calculate its percentage and display the grade. Source code: #include int main() { int sub1,sub2,sub3,sub4,sub5; printf("Enter sub1 marks:"); scanf("%d",&sub1); printf("Enter sub2 marks:"); scanf("%d",&sub2); printf("Enter sub3 marks:"); scanf("%d",&sub3); printf("Enter sub4 marks:"); scanf("%d",&sub4); printf("Enter sub5 marks:"); scanf("%d",&sub5); float t_marks=(sub1+sub2+sub3 +sub4+sub5)/5; float perct=t_marks*100; if(perct > 75) { printf("Grade: A"); } else if(perct > 60 && perct = 50 && perct Output: Enter sub1 marks:100 Enter sub2 marks:100 Enter sub3 marks:100 Enter sub4 marks:100 Enter sub5 marks:100 Grade: A

C program to calculate Simple Interest.

Question: Write a C program to calculate simple Interest of a amount. Source code: #include void main() { float principal_amount,rate, time,simple_interset; printf("Enter principal_amount:"); scanf("%f",&principal_amount); printf("Enter rate:"); scanf("%f",&rate); printf("Enter time:"); scanf("%f",&time); simple_interset= (principal_amount*rate*time)/100; printf("simple_interset:%f", simple_interset); } Output: Enter principal_amount:1000 Enter rate:3 Enter time:2 simple_interset:60.000000

C program to calculate area and perimeter of Circle.

Question: Write a C program to take a radius from user and calculate the area and perimeter of circle. Source code: #include void main() { int rad; float perimeter,area; printf("Enter radius :"); scanf("%d",&rad); perimeter=2*3.14*rad; area=3.14*rad*rad; printf("Perimeter:%f \n",perimeter); printf("Area:%f",area); } Output: Enter radius :4 Perimeter:25.120001 Area:50.240002

First 'Hello World!' program in C.| DataType | Header |

Image
'HelloWorld!' Program. #include //header file void main() { printf("HelloWorld!"); } Keywords: It define as the set of specific word which meaning are predefined in system(Language). Example: int, long, for, double, while, do, static, main, float, if, case, break etc. Header File: Header file is defined as the collection of different system define function. stdio.h, conio.h, dos.h, string.h, stdlib.h, math.h etc. main() It is core of every program. It contains instructions that tell to the computer to carry out what ever task your program is designed to do. DataType  

Switch Case in javascript.

Switch Case: Switch case statement is used to select one of many blocks of code to be executed. Syntax: Switch(expression) { case 'condition': Block statement(s); break; case 'condition2': Block statement(s); break; case 'condition3': Block statement(s); break; ..................... ..................... case 'condition n': Block statement(s); break; default: Block statement(s); break; } Example: Write a program in javascript to display message depending on which day of the week it is using switch case. switch case output: PRACTICAL

Built in functions in Python.

Built in functions: sum() sum () function is used to add the all elements of list. marks=[70,60,55,80,75] temp=sum(marks) print(temp) avg=float(temp/len(marks)) print(avg) output: 340 68.0 len() This method is used to find the length of given list. l1=[10,20,30,40,50] print(len(l1)) output: 5 max() This method is used to find the maximum value present in list. l1=[10,20,30,40,50] print(max(l1)) output: 50 min() This method is used to find the minimum value presentin the list. l1=[10,20,30,40,50] print(min(l1)) output: 10 shuffle() This method is used to shuffle the value present in the list. To used the memthod shuffle, we have to import module. import random l1=[10,20,30,40,50] random.shuffle(l1) print(l1) output: [50, 10, 30, 40, 20] join() To join the individual characters of the list if it is a string. We can combined the character into long string. str=['P',...

Built in Methods in Python.

BUILT IN METHOD: append() append() method add a list item in the end of list. books=['java','python','DBMS','Ds'] print(books[2:4]) books.append('os') print(books) output: ['DBMS', 'Ds'] ['java', 'python', 'DBMS', 'Ds', 'os'] Count() Count() return the numbers of time x apper in list. m1=[1,2,3,1,5,6,1] print(m1) print(m1.count(1)) output: [1, 2, 3, 1, 5, 6, 1] 3 Clear() It will remove all the item from list. m1=[1,2,3,4] print(m1) m1.clear() print(m1) output: [1,2,3,4] [] Copy() This method is used to return a same copy of the list. l1=['a','b','c'] print(l1) l2=l1.copy() print(l2) output: ['a','b','c'] ['a','b','c'] extend(object x) append all element of the list l2 to the list l1 or vice-versa. ...

List Slicing & List Operations in python..

List Slicing: The slicing operator return a subset of list called slice, by specifying start and end indexes. Syntax: list_variable_name [start:end] Creating List without using Constructor: list1=['ram','shyam',23,45,67,20.05] print(list1[1:4]) print(list1[2:5]) print(list1[:3]) print(list1[:]) print(list1[::-1]) print(list1[2::]) Output: ['shyam', 23, 45] [23, 45, 67] ['ram', 'shyam', 23] ['ram', 'shyam', 23, 45, 67, 20.05] [20.05, 67, 45, 23, 'shyam', 'ram'] [23, 45, 67, 20.05] List slicing with step-size: The third parameter step-size is to select list with step-size. Syntax: name_of_list_variable [staert:end:step] Example: list1=['ram','shyam',23,45,67,20.05] print(list1[0:4:2]) Output: ['ram', 23] List Operations: Traversing a List: To traverse a list we use "for in" statement which make it easy to loo...

List in Python...|empty list | retrieve list.

List: In python a list is a sequence of values called items or elements. The elements can be any datatype like integer,string or float values. The items or elements are placed between the '[]',separated with ','. Creating List: The list class define List. A programmer can use list constructor to create a list. l1=list() l2=list(['b',1,2,3,4,'A']) l3=list([1,2,3,4,5,6.06]) print(l1) print(l2) print(l3) Output: [] ['b', 1, 2, 3, 4, 'A'] [1, 2, 3, 4, 5, 6.06] Creating List without using Constructor: l1=[] l2=['b',1,2,3,4,'A'] l3=[1,2,3,4,5,6.06] print(l1) print(l2) print(l3) Output: [] ['b', 1, 2, 3, 4, 'A'] [1, 2, 3, 4, 5, 6.06] Retrieve the elemements of List : The elements of list are access by index operator. Syntax: name_of_list_variable [index] Example: l1=["Python","Code",2020] print(l1[0]) print(l1[1]) print(l...

A simple Python Game..

Image
Source Code: attemp=int(input("Enter Attempts:")) no_attept=attemp guessContainer="Harshwardhan" while attemp > 0: guessword=input("Guess Character:") failed=0 if guessword in guessContainer: print("Correct Guess") else: print("Incorrect Guess") failed=failed + 1 attemp=attemp-1 if failed > no_attept/2: print("You failed..") else: print("you won") Output:  

Positional and Keyword Argument in python.

Positional Argument If there are more then one parameters are present in a function, how does python idenify which argument in the statement has to assign which parameter. The parameter are assign accordings to their position i.e. first argument in the first column. Example 1: def display(name,mobile_no): print("Name:",name) print("Mobile_number:",mobile_no) display("Harsh",123456) Output: Name: Harsh Mobile_number: 123456 Example 2: def display(name): print("Name:",name) display("Harsh",123456) Error: Traceback (most recent call last): File " ", line 7,in TypeError:display()takes 1 positional argument but 2were given Keyword Argument An alternative to positional argument is keyword argument. If the program knows the parameter name use within the function then they can use the parameter name by calling the function. This is done by: Parameter_name=value ...

Python Function.. Parameter, Arguments,Factorial of number.

Function: It is difficult to maintain large scale program and the identification of the programming gets harder. The best way to create programming application is to divide a big program in small module and repeatedly call this module within program with the help of function and entire program can be devide into small independent modules. A function is the self contained block of one or more statement that perform a special task when called. This improve the code readability as well as flow of execution and small modules can be managed easily. Syntax: def function_name (list_parameter): statement(s) the syntax for the python contains header and the body. The function header begins with the header 'def' followed by the function name and arguments are optional. the body contents the statement to be executed and function will be executed only when it is being called. Example: Write a python program to display a simple message Source ...

Testing of a String.|String methods|

A string may contain digit, alphabet or combination of both of this. This various methods are available to test if the entered string is digit or alphabets or alphanumeric. bool isalnum: str=input("enter string") print(str) print(str.isalnum()) output: enter string:harsh harsh True bool isalpha: str="123python" str1="python" print(str.isalpha()) print(str1.isalpha()) output: False True bool isdigit: str="123" str1="python" print(str.isdigit()) print(str1.isdigit()) output: True False bool islower: str="PYTHON" str1="python" print(str.islower()) print(str1.islower()) output: False True bool isupper: str="PYTHON" str1="python" print(str.isupper()) print(str1.isupper()) output: True False bool isspace: str=" " str1="python" print(str.isspace()) print(str1...

Searching of String in Python.|methods|sub-strings.

Searching of String. This is the process of checking occurance of substring in whole string or in a substring finding the characyers if starting index BEG and End ending index are given. Syntax: str_var.find("string",beg=0,end=len(string)) where string specify,string to be search beg specify starting index by default it is 0. end specify is ending index by default it is length of string. Here, return value of this function will be an index if found or -1 otherwise. Example: str="python" print(str) print(str.find("y")) output: python 1 Various methods of string class is used to search the substring in a given string. bool endswith(str1,str2) str="python basic" print(str) print(str.endswith("basic")) output: python basic True bool startswith(str1,str2) str="python basic" print(str) print(str.startswith("python")) output: python basic...

String Operations in Python. |print all letters appear in two words|

String contains the slicing operator and the slicing with the stepsize parameter is used to obtain the subset of string. It also has basic concatination " + " in and repeatation " * ". String Slicing Operators The slicing operator return a subset of string called slice by specifying two indexes start and end. Syntax: Var_name[start:end] Example: st="python string" print(st[4:10]) output: on str String Slicing with step size If the programmer select every second character from string. This can be done by using step-size. We need to add third parameter as step-size. Syntax: Var_name[start:end:stepsize] Example: st="python basic string" print(st[1:10:2]) output: yhnbs Some more Complex examples: st="python basic string" print(st[::]) print(st[::-1]) print(st[-1::-1]) print(st[:-1]) output: python basic string gnirts cisab nohtyp gnirts cisab nohtyp p...

Control statements(Break, Continue, Pass) in Python.

Control Statement Control statement allow a programmer to control the flow of program according to their need. Control statements are break, continue and pass. Break Statement The break statement allow a programmer to terminate a loop, when the break statement is encountered inside the loop,the loop is immidiately terminated and program control automatically goes to first statement. Break statement in while loop Syntax: while test_condition: statement(s) if test_condition: break statement(s) Break statement in for loop Syntax: for variable_name in Sequence: //Loop_Body if test_condition: break //Loop_Body //Statement after Loop Write a program to demonstrate the use of break statement. Syntax: print("The number from 1 to 5") for num in range(1,100): if num==4: break else: print(num) output The number from 1 to 5 1 2 3 Continue Statement The continue Statement is exactly opp...

How to identify the consonants in string? |String | Python Code.

Source Code st=input("Enter your string ") vowel="aeiouAEIOU" l1=[] for i in st: if(i not in vowel): l1.append(i) print("Consonants in given String") print (l1) output Enter your string hello Consonants in given String ['h', 'l', 'l']

HTML. |create a beautiful web page |Learn HTML.

How to work with HTML HTML stands for HyperText Markup Language, HTML is used to create the web pages. Any Text editors like Notepad, Notepad++, SublineText etc. are used to write html code. We can use many programming languages with the html for creating wonfderful dynamic web pages. For design purpose we use CSS to create a beautiful web pages. Basic Structure: //Title for web page //Body Block(s) HTML Tag First one is tag, thhis is the entry point to design the other tages. All the other tags should be placed between Head Tag Second tag is head tag in which we write header part of our web page. We include title tag between this head tag,we can add multiple links which is used in the web page Title Tag Third tag is title tag , to give the title to the page title tag is used. First WebPage Body T...

Hello World! First Java Program.

Java 'Hello World!' Program. Java is an Object Oriented Programming language and java program uses Class for all the programs so for a simple printing 'Hello world!' also we needed Class. Source Code import java.lang.*; public class MyFirstProgram{ public static void main(String []args){ System.out.println("Hello World"); } } Output Hello World

Flow Chart in Programming language | C,C++,Python.

Image
Flow chart. Flow chart is defien as the flow of a program , Flow chart show the actual internal execution of the profram Following compnenet of the chart as follows:   Example: Draw the flow chart to compare two or three numbers.  

Loops in Python.

Looping Looping is a continuous execution of a statement till the condition becomes false or till it set the end point. In python two types of looping supported , they are: 1. While Loop 2. For Loop While loop While loop is a conditional control statement. It will be executed based on the condition, if the condition is true it will execute the body of the loop till the condition become false Syntax: while condition: Block Statement increment/decrement Example: Write a python program to add 10 consecutive number starting from 1 using while loop. Syntax: count=0 sum=0 while count output: sum of 10 consecutive numbers is : 55 For loop The for loop in python a slightly different from other programming language. The python for loop iterate through each value in a sequence,where squence of object hold multiple items of data store one after another. Syntax: for variable_name in sequence: statement(...

Decision Making Statement.

Image
Conditional Statement Decision making of an anticipation of condition occuring by execution of program and dpecific action is taken according to condtion. Following is a general form of typical decision making structure found in most programming language. Python programming language uses any non-zero or non-null value as true and if it is either zero or null then it is assume false value. if Condition: In python the block of statement is executed if the condition is true. Syntax if (condition): Block(s) Example var1=100 if var1: print('i got an true value') print(var1) output i got an true value 100 Question: Write a program that prompt user to enter two integer values, print the message "equal" if both entered value are equal a=int(input("Enter first number")) b=int(input("Enter second number")) if a==b: print("equal") output Enter fir...

Introduction to Python.

What is python? Python is an object-oriented programming language created by Guido Rossum in 1998. If you just beginning your programming career, python suits you best. With python you can do everything from GUI developement, web application, Machine learning, IOT, Game Developement etc. so it is general purpose high level programming language. It is very easy language,it is good for beginners. It is case sensitive language. Python is Dynamically Typed, Write less code do more. Introduction Easy to Learn and Use Python is easy to use and learn, it is user friendly and high level programming language. Expressive language Pyton language is more expressive means that is more understand and readable. Unique style Python is an interpreted language i.e interpreter execute the code line by line at a time . This makes debugging easy and thus suitable for beginners. Cross Platform Language Python can run equally on different platform such as windows, Linu...

Tower of Henoi Algorithm.

Image
Tower of Hanoi: Tower of Henoi It is a mathematical puzzle in which three towers and more than one different sizes rings are stacked in ascending order. In this puzzle number of disc can be increases. Disc are kept in this way that smaller disc sits over bigger disc. Rules to Play: The task of this puzzle is to move the discs to another tower without breaking the sequence of arrangement. 1. Only one disc can be move at a time. 2. Only upper disc can be move. 3. Bigger disc can not be sit over small disc. Source code: def towerOfHenoi(n, source, to,intermediate): if(n==1): print("Transfer disc", source ,"to", to) else: towerOfHenoi(n-1,source,intermediate,to) print("Transfer disc", source ,"to", to) towerOfHenoi(n-1,intermediate,to,source,) numOfdisc=int(input("Enter number of disc")) towerOfHenoi(numOfdisc,'A...

Dictionary in python.

Image
Dictionary ({}) Python provide dictionary structure to deal with key and value as pair. It is a container which contains data in pair of '{ }'. The pair key and value is known as Item. The key and value must be separated by ':' and each pair of item is separated by ' , '. Different item s are enclosed within '{ }' and this create dictionary Example: D={101:'AAA',102:'BBB',103:'CCC'} print(D) output: {101:'AAA',102:'BBB',103:'CCC'} The value in the dictionary are mutable i.e it can be change however the key is immutable and must be unique for every item. The key is used to access the specific value. The values can be updated but the key can not be changed. The dictinary is also known as Associated Array. Example: Create a program for dictionary and print any two value using its key and update a value using key and print again. a={name:...