Found 34494 Articles for Programming

Fraction module in Python

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

5K+ Views

In Python the Fraction module supports rational number arithmetic. Using this module, we can create fractions from integers, floats, decimal and from some other numeric values and strings. There is a concept of Fraction Instance. It is formed by a pair of integers as numerator and denominator. The class fractions.Fractionis used to create a Fraction object. It takes Numerator and Denominator. The default value of the numerator is 0 and denominator is 1. It raises ZeroDivisionError when the denominator is 0. At first we will see how the class can create fractions using Numerator and Denominator. Example code Live ... Read More

First Class functions in Python

Samual Sam
Updated on 30-Jul-2019 22:30:23

2K+ Views

In different programming languages, First Class objects are those objects, which can be handled uniformly. First Class objects can be stored as Data Structures, as some parameters of some other functions, as control structures etc. We can say that a function in Python is First Class Function, if it supports all of the properties of a First Class object. What are the properties of First Class Functions? It is an instance of an Object type Functions can be stored as variable Pass First Class Function as argument of some other functions Return Functions from other function Store Functions in ... Read More

C# Program to create Pascal’s Triangle

Chandu yadav
Updated on 26-Jun-2020 14:45:44

4K+ Views

A Pascal’s triangle contains numbers in a triangular form where the edges of the triangle are the number 1 and a number inside the triangle is the sum of the 2 numbers directly above it.A program that demonstrates the creation of the Pascal’s triangle is given as follows.Example Live Demousing System; namespace PascalTriangleDemo {    class Example {       public static void Main() {          int rows = 5, val = 1, blank, i, j;          Console.WriteLine("Pascal's triangle");          for(i = 0; i

C# program to implement FizzBuzz

George John
Updated on 20-Apr-2020 08:06:26

3K+ Views

Implementation of FizzBuzz involves printing numbers from 1 to 100. If the numbers are multiples of 3 then Fizz is printed. If they are multiples of 5, then Buzz is printed and if they are multiples of both 3 and 5 then FizzBuzz is printed.A program that demonstrates the implementation of FizzBuzz is given as follows.Example Live Demousing System; namespace FizzBuzzDemo {    public class example {       static void Main(string[] args) {          for (int i = 1; i

How to get synonyms/antonyms from NLTK WordNet in Python

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

2K+ Views

The WordNet is a part of Python's Natural Language Toolkit. It is a large word database of English Nouns, Adjectives, Adverbs and Verbs. These are grouped into some set of cognitive synonyms, which are called synsets. To use the Wordnet, at first we have to install the NLTK module, then download the WordNet package. $ sudo pip3 install nltk $ python3 >>> import nltk >>>nltk.download('wordnet') In the wordnet, there are some groups of words, whose meaning are same. In the first example, we will see how wordnet returns meaning and other details of a word. Sometimes, if some ... Read More

Heap Sort in C#

Ankith Reddy
Updated on 26-Jun-2020 14:27:51

2K+ Views

Heap Sort is a sorting algorithm that makes use of the heap data structure. Each time the root element of the heap i.e. the largest element is removed and stored in an array. It is replaced by the rightmost leaf element and then the heap is reestablished. This is done until there are no more elements left in the heap and the array is sorted.A program that demonstrates heap sort in C# is given as follows.Example Live Demousing System; namespace HeapSortDemo {    public class example {       static void heapSort(int[] arr, int n) {         ... Read More

Chaining comparison operators in Python

Samual Sam
Updated on 30-Jul-2019 22:30:23

707 Views

Sometimes we need to use more than one condition checking in a single statement. There are some basic syntax for these kind of checking is x < y < z, or if x < y and x < z etc. Like other languages, there are some basic comparison operators in Python. These comparison operators are =, ==, !=, is, is not, in, not in. The precedence of these operators are same, and the precedence is lesser than arithmetic, bitwise and shifting operators. These operators can be arranged arbitrarily. They will be used as a chain. So for an example, if ... Read More

Insertion Sort in C#

Arjun Thakur
Updated on 26-Jun-2020 14:30:08

4K+ Views

Insertion Sort is a sorting algorithm that takes an element at a time and inserts it in its correct position in the array. This process is continued until the array is sorted.A program that demonstrates insertion sort in C# is given as follows.Example Live Demousing System; namespace InsertionSortDemo {    class Example {       static void Main(string[] args) {          int[] arr = new int[10] { 23, 9, 85, 12, 99, 34, 60, 15, 100, 1 };          int n = 10, i, j, val, flag;          Console.WriteLine("Insertion Sort");   ... Read More

Quickly convert Decimal to other bases in Python

AmitDiwan
Updated on 11-Aug-2022 11:31:07

1K+ Views

To quickly convert Decimal to other based, we will be using the Built-in functions in Python − Decimal to Binary − bin() Decimal to Octal − oct() Decimal to Hexadecimal − hex() Decimal number system has base 10 as it uses 10 digits from 0 to 9. In decimal number system, the successive positions to the left of the decimal point represent units, tens, hundreds, thousands, and so on. Binary uses two digits, 0 and 1. Also called as base 2 number system Each position in a binary number represents a 0 power of the base (2). Last ... Read More

Selection Sort program in C#

Chandu yadav
Updated on 26-Jun-2020 14:32:38

5K+ Views

Selection Sort is a sorting algorithm that finds the minimum value in the array for each iteration of the loop. Then this minimum value is swapped with the current array element. This procedure is followed until the array is sorted.A program that demonstrates selection sort in C# is given as follows.Example Live Demousing System; public class Example {    static void Main(string[] args) {       int[] arr = new int[10] { 56, 1, 99, 67, 89, 23, 44, 12, 78, 34 };       int n = 10;       Console.WriteLine("Selection sort");       Console.Write("Initial array ... Read More

Advertisements