Python Program to Add Two Numbers.

Given two numbers num1 and num2. Write a Python program to perform the addition of given two numbers and print the output sum.

Example:

Given: num1 = 10, num2 = 20
Output: 30

Given: num1 = 5, num2 = 8
Output: 13


Example Python Code:

# take input from the user
num1 = input("Enter a number: ")
num2 = input("Enter another number: ")

# add the two numbers
sum = float(num1) + float(num2)

# print the result
print("The sum of {0} and {1} is {2}".format(num1, num2, sum))
Output:
Enter a number: 12
Enter another number: 41
The sum of 12 and 41 is 53.0

Explanation:
This program takes two numbers as input from the user using the input() function, which returns the input as a string. The input is then converted to a float using the float() function so that the numbers can be added together. 

The result is stored in the variable sum, which is then printed out using the print() function. The format() method places the values of num1, num2, and sum into the string.

How To Create Hyperlink in HTML?

HTML links, also known as hyperlinks, allow users to navigate between web pages or different sections of a web page by clicking on text or images.


Adding Link to a Text.

The most basic way to create a link in HTML is to use the <a> (anchor) element. The <a> element has an "href" (hypertext reference) attribute that specifies the URL or web address of the page or resource that the link should point to.

Example:

<a href="https://www.example.com">Visit example.com</a>
Output:


Adding Jump Link to a section of the Page.

You can also use the <a> element to create links to specific locations within a web page. To do this, you would use the "name" attribute and the "#" symbol, followed by the name of the location you want to link to. Then, you would create the location by using the "name" attribute on the element that you want to link to.

Example:
<a href="#section1">Go to section 1</a>
...
<h2 name="section1">Section 1</h2>

Adding Link to an Image.

You can also use the <img> element to link an image. In this case, the <img> element should be nested within the <a> element and the <img> element should have an "src" attribute that specifies the URL of the image file.

Example:
<a href="https://www.example.com">
    <img src="example.jpg" alt="Example">
</a>

It's important to note that the <a> element should always have a closing tag </a> and the value of the "href" attribute must always be enclosed in quotation marks.

Heap Sort Algorithm in C++

In this post, we are going to understand Heap sort which is similar to the selection sort algorithm for sorting data.


Heap sort is a comparison-based sorting algorithm that uses a binary heap data structure to sort an array. A binary heap is a complete binary tree that satisfies the "heap property," which states that the value of each node is greater than or equal to the values of its children (for a max-heap) or less than or equal to the values of its children (for a min-heap).


The basic steps of the heap sort algorithm in C++:

Step 1. Build a max-heap from the input array.

void build_max_heap(int arr[], int n) {
    for (int i = n / 2 - 1; i >= 0; i--)
        heapify(arr, n, i);
}

Step 2: Swap the root (maximum value) of the heap with the last element of the array. This moves the maximum value to the end of the array. Then, call the heapify function on the remaining elements, except the last one, to maintain the heap property.

void heap_sort(int arr[], int n) {
    build_max_heap(arr, n);

    for (int i = n-1; i >= 0; i--) {
        swap(arr[0], arr[i]);
        heapify(arr, i, 0);
    }
}

Step 3: The heapify function is used to maintain the heap property. It compares the value of the node with its children and if the value of the node is less than the value of its children, it swaps the values of the node with the largest value among its children.

void heapify(int arr[], int n, int i) {
    int largest = i;
    int l = 2*i + 1;
    int r = 2*i + 2;

    if (l < n && arr[l] > arr[largest])
        largest = l;

    if (r < n && arr[r] > arr[largest])
        largest = r;

    if (largest != i) {
        swap(arr[i], arr[largest]);
        heapify(arr, n, largest);
    }
}

Complete C++ Program for Heap Sort.
//C++ Example for Heap Sort Algorithm
#include<iostream>
using namespace std;

void heapify(int arr[], int n, int i) {
    int largest = i;
    int l = 2*i + 1;
    int r = 2*i + 2;

    if (l < n && arr[l] > arr[largest])
        largest = l;

    if (r < n && arr[r] > arr[largest])
        largest = r;

    if (largest != i) {
        swap(arr[i], arr[largest]);
        heapify(arr, n, largest);
    }
}
//function to build max heap
void build_max_heap(int arr[], int n) {
    for (int i = n / 2 - 1; i >= 0; i--)
        heapify(arr, n, i);
}
//heap sort function
void heap_sort(int arr[], int n) {
    build_max_heap(arr, n);

    for (int i = n-1; i >= 0; i--) {
        swap(arr[0], arr[i]);
        heapify(arr, i, 0);
    }
}

int main()
{
    int arr[] = {3, 8, 1, 4, 2, 11};
    int n = sizeof(arr)/sizeof(arr[0]);

    heap_sort(arr, n);

    for(int i = 0; i < n; i++)
       cout<<arr[i]<<" ";

    return 0;   
}
Output:
1 2 3 4 8 11
  • Time Complexity: O(n log n)
  • Space Complexity: O(1)
Heap sort is better than bubble sort and selection sort but not better than insertion sort.

Colors in HTML

Colors play an essential role in web design, and HTML provides several ways to specify colors for different elements on a web page. In this article, we will discuss the different ways to specify colors in HTML, and some best practices to keep in mind when using colors in web design.


There are three main ways to specify colors in HTML: 

  • Using Color names.
  • Using Hex codes.
  • Using RGB values.


Using Color names.

Color names are the simplest way to specify colors in HTML. There are 140 predefined color names in HTML such as "red", "green", "blue", etc. To use a color name, specify the color name as the value of the "color" property. 


For example, to set the text color of a paragraph to red, you would use the following code:

<p style="color: red">This paragraph text is red</p>
Output:
Color name in HTML

Using Hex codes.

Hex codes are another way to specify colors in HTML. A hex code is a six-digit code that represents a color in the RGB color model. To use a hex code, prefix it with a "#" symbol and specify it as the value of the "color" property. 

For example, to set the text color of a paragraph to dark blue, you would use the following code:
<h2 style="color: #0ebd4b">This is a sub-heading</h2>
<p style="color: #00008b">This paragraph text is dark blue</p>
Output:
Hex Code in HTML

Using RGB Values.

RGB stands for Red, Green, and Blue and is a way to represent colors in HTML. The RGB color model is an additive color model in which red, green and blue light are added together in various ways to reproduce a broad array of colors.

In HTML, RGB colors can be specified using the "rgb()" function in a CSS "color" or "background-color" property. The function takes three values, one for each of the color's red, green, and blue components, and must be in the range of 0-255.

Example:
<p style="color: rgb(255, 0, 0);">This text is red.</p>
<div style="background-color: rgb(0, 255, 0);">This background is green.</div>
Output:
RGB Color in HTML

You can also use a variation called RGBA which stands for Red, Green, Blue, and Alpha, which is a value between 0 and 1 representing the opacity of the color.

Example:
<p style="color: rgba(255, 0, 0)">This text is red with 100% opacity</p>
<p style="color: rgba(255, 0, 0, 0.5)">This text is red with 50% opacity</p>
Output:
RGBA color in HTML


C++ Program to Find Simple Interest

Simple interest is calculated by multiplying the principal amount, the interest rate, and the time period. The formula for simple interest is:

I = (P * R * T) / 100

Where I is the interest, P is the principal amount, R is the interest rate, and T is the time period.


Here is an example C++ program that calculates the simple interest:

//C++ Example Program to find Simple Interest
#include <iostream>
using namespace std;

int main() {
    float P, R, T, I;

    // Input the principal amount, interest rate, and time period
    cout << "Enter the principal amount: ";
    cin >> P;
    cout << "Enter the interest rate: ";
    cin >> R;
    cout << "Enter the time period: ";
    cin >> T;

    // Calculate the simple interest
    I = (P * R * T) / 100;

    // Display the result
    cout << "Simple Interest = " << I;

    return 0;
}
Output:
Enter the principal amount: 10000
Enter the interest rate: 10
Enter the time period: 5
Simple Interest = 5000

In this example, the user is prompted to input the principal amount, interest rate, and time period. The program then calculates the simple interest using the formula and displays the result.

Also read:

Comments in HTML. (Shortcut Key)

Comments play an important role in coding, they help developers understand, organize, and maintain their codebase. In HTML, comments serve as annotations within the code, offering, insights, explanations, and reminders without affecting the displayed content. Let's understand their types, usage, and essential shortcuts. 


Why Use Comments in HTML?

In HTML, comments are used to add notes or explanations to the source code of a web page. They serve multiple purposes:

  • They help document the code, providing explanations for specific sections or lines.
  • They improve code readability, assisting developers in comprehending complex or intricate structures.
  • Comments can be used to identify or isolate issues within the code during troubleshooting or debugging processes.
  • They facilitate collaboration among developers by conveying intentions, strategies, or notes within the code.

Types of Comments in HTML.

Comments are not displayed in the browser and are ignored when the page is rendered. HTML supports two types of comments:

1. Single-line Comments: Denoted by <!-- -->, single-line comments are used for brief annotations on a single line. 

Example of Single-line Comment:

<!DOCTYPE html>
<html>
  <head>
    <title>HTML Comment Example</title>
  </head>
  <body>
    <!--This is a single line comment in HTML-->
    <h2>This is a Heading.</h2>
    <h3>Welcome to AlgoLesson</h3>
  </body>
</html>

Output:


2. Multi-line Comments: Enclosed between 
<!-- and closing -->, multi-line comments span across multiple lines and are useful for detailed explanations or larger annotations. Comments can be added anywhere within the HTML code and can span multiple lines.

Example of Multi-line Comment:
<!DOCTYPE html>
<html>
  <head>
    <title>HTML Comment Example</title>
  </head>
  <body>
    <!--This is a multi-line comment in HTML
        This will not be displayed on the browser screen-->
    <h2>This is a Heading.</h2>
    <h3>Welcome to AlgoLesson</h3>
  </body>
</html>

Inline Comment in HTML

In HTML, comments can be also used inside the content or in the middle of the code. 

Example: 
<p>This is a simple paragraph in HTML.</p>
<p>This an example of <!--comment inside--> HTML content.</p>
Output:
Inline Comment in HTML

HTML Comment Shortcuts.

While various text editors and IDEs offer shortcuts to insert comments easily, some widely used keyboard shortcuts for adding comments in HTML are:
  • Visual Studio Code: Ctrl + / (Windows/Linux) or Cmd + / (Mac) to toggle comments for selected lines.
  • Sublime Text: Ctrl + / (Windows/Linux) or Cmd + / (Mac) to toggle comments for selected lines.
  • Notepad++: Ctrl + Shift + Q to add or remove comments for selected lines.

I hope that now you understand how to use Comments in HTML and why they are so important for developers. It helps us create a clean, maintainable, and well-documented codebase.

Quotation and Citation Elements in HTML

In HTML, there are multiple elements that are used for Quotation and Citation and these are:

  • <blockquote>
  • <q>
  • <abbr>
  • <address>
  • <cite>
  • <bdo>

HTML <blockquote> Element

The <blockquote> tag in HTML is used to indicate a section of text that is quoted from another source. The text within the <blockquote> tags will be indented and typically displayed in a slightly different style to set it apart from the rest of the document. The <blockquote> tag should include a source citation using the cite attribute and the footer tag.

Example:

<p>Quote for the day:</p>
<blockquote cite="https://en.wikipedia.org/wiki/Steve_Jobs">
   <p>Innovation distinguishes between a leader and a follower.</p>
</blockquote>
Output:
blockquote tag in HTML

HTML <q> Element

The <q> tag in HTML is used to define smaller quotations and it is displayed by quotation marks around the quote.

Example:
<p>Quote for the day:</p>
<p><q>Programming is like any other sport.</q></p>
Output:
q tag in HTML

HTML <abbr> Element.

The <abbr> tag in HTML is used to indicate an abbreviation or acronym. The tag should include the full form of the term in the title attribute, which will be displayed as a tooltip when a user hovers over the abbreviation.

Example:
<p>The <abbr title="World Wide Web">WWW</abbr> was invented in 1989.</p>
Output:

The WWW was invented in 1989.

In this example, "WWW" is the abbreviation, and "World Wide Web" is the full form of the term. When a user hovers their cursor over the "WWW" it will show the full form of "World Wide Web"


HTML <address> Element

The <address> tag is used to provide contact information for the document or the nearest article or section. It typically contains information such as the author's name, email address, and physical address. 
The text within the <address> tag is typically rendered in italics by web browsers. The <address> tag should be used within the <body> section of an HTML document and can be placed anywhere within the document. (alert-passed)
Example:
<body>
    <address>
      Written by Mohan Dev.<br />
      Visit us at:<br />
      Example.com<br />
      Box 564, Delhi<br />
      INDIA
    </address>
</body>
Output:
address tag in HTML

HTML <cite> Element

The <cite> tag is used to indicate the title of a creative work, such as a book, poem, play, song, movie, or painting. It is typically used to cite the source of a quote or reference in an HTML document. 

The text within the <cite> tag is typically rendered in italics by web browsers. The <cite> tag should be used within the <body> section of an HTML document.

Example:
<p>As Shakespeare wrote in his play <cite>Hamlet</cite>, "To be or not to be, that is the question."</p>
Output:
cite in HTML

HTML <bdo> Element

The <bdo> (bidirectional override) tag is used to change the direction of the text display. It is used to override the default bidirectional behavior of text, which is determined by the Unicode bidirectional algorithm. 

The dir attribute is used to specify the direction of the text and can have values of "ltr" (left-to-right) or "rtl" (right-to-left). The text within the <bdo> tag will be displayed in the specified direction, regardless of the surrounding text.

Example:
<p>This text is left-to-right: <bdo dir="ltr">Hello World!</bdo></p>
<p>This text is right-to-left: <bdo dir="rtl">Hello World!</bdo></p>
Output:
bdo tag in HTML


Formatting in HTML

Formatting in HTML refers to the process of arranging and styling text and other content on a webpage. HTML provides a number of tags and attributes that can be used to format text, including headings, paragraphs, lists, and more.


One of the most basic formatting tags in HTML is the <p> tag, which is used to create paragraphs of text. The p tag automatically adds a line break before and after the text, creating a distinct block of text.

<p>This is a paragraph text</p>
<p>This is another paragraph text</p>


List of Formatting Elements:

  • <br/>: Line break.
  • <b>: Bold text
  • <strong>: Important text
  • <i>: Italic text
  • <u>: unarticulated text
  • <em>: Emphasized text
  • <mark>: Marked text
  • <small>: Smaller text
  • <del>: Deleted text
  • <ins>: Inserted text
  • <sub>: Subscript text
  • <sup>: Superscript text


HTML <br/> Element.

The <br/ > element is used to insert a single-line break and mainly use for writing addresses or poems.

Example:
<p>This is paragraph for showing example of <br /> line break.</p>
Output:
line break HTML example

HTML <b> and <strong> Element.

Both are used to define bold text where <b> element is used to define bold text without importance and <strong> element is used to define bold text with greater importance.

Example:
<p>This is simple text</p>
<p><b>This is a bold text</b></p>
<p><strong>This is a bold and important text</strong></p>
Output:
bold text in HTML

HTML <i>, <u> and <em> Elements.

The <i> tag in HTML is used to represent a portion of text in italic. It is used to show voice, technical terms, or part of the text written in another language. 

Example:
<p>This is a simple paragraph</p>
<p><i>This is an italic text</i></p>
Output:
italic text in HTML


The <u> tag in HTML stands for underline and is used to underline the text. It is generally used to underline misspelled words in a paragraph.

Example: 
<p>This is a <u>simple</u> paragraph</p>
Output:
underline text in HTML

The <em> tag in HTML stands for emphasized text and the content inside this is displayed in italic font.

Example: 
<p>This is an simple paragraph</p>
<p><em>This is an emphasized paragraph</em></p>
Output:
emphasized text in HTML

HTML <small> Element.

The <small> tag in HTML is used to define smaller text. 

Example: 
<p>This is a simple paragraph</p>
<p><small>This is smaller paragraph</small></p>
Output:
small text in HTML

HTML <mark> Element

The <mark> HTML tag is used to highlight a portion of text.

Example:
<p>The speed limit of this road is <mark>40KM/hr</mark>.</p>
Output:
highlight text in HTML


HTML <del> Element

The <del> tag in HTML is used to represent the portion of text that has been deleted. 

Example:
<p>I love playing <del>cricket</del> football</p>
Output:
strike text in HTML

HTML <sub> Element

The <sub> tag in HTML is used to create subscript text, which is a text that is slightly smaller and appears slightly lower than the surrounding text. Subscript text is often used in mathematical or scientific equations to indicate a value or variable that is to be used as the base of power or index.

Example:
<p>This is an equation: x<sub>1</sub> + x<sub>2</sub> = x<sub>3</sub></p>
Output:
subscript text in HTML

HTML <sup> Element

The <sup> tag in HTML is used to create superscript text, which is text that is slightly smaller and appears slightly higher than the surrounding text. Superscript text is often used in mathematical or scientific equations to indicate exponents, footnotes, or other similar uses.

Example:
<p>This is an equation: x<sup>2</sup> + y<sup>2</sup> = z<sup>2</sup></p>
Output:
subscript text in HTML


DON'T MISS

Nature, Health, Fitness
© all rights reserved
made with by templateszoo