This tutorial will discuss how to write a Swift program to find LCM of two numbers. LCM is also known as Least Common Multiple. It is used to calculate the smallest common multiple between two or more numbers. Here common multiple represents a number which is multiple of two or numbers. For example, we have two numbers 10 and 8 Factor of 10 = 2 x 5 Factor of 8 = 2 x 2 x 2 Union of both factors = 2 x 2 x 2 x 5 = 40 So the LCM of 10 and 8 is 40. This ... Read More
This tutorial will discuss how to write a Swift program to find GCD of two numbers. GCD is also known as Greatest Common Divisor or HCF(Highest common factor). GCD of two positive number is defined as the greater positive number which is the common factor of both the given two positive numbers. The value of GCD cannot be 0 or negative. The minimum value of GCD of two numbers is always 1. For example, we have two numbers 24 and 30. Factor of 24 = 2 x 2 x 2 x 3 Factor of 30 = 2 x 3 x ... Read More
This tutorial will discuss how to write a Swift program to round a number to n decimal places. Rounding a number means round a decimal number to a certain number of decimal places or we can say round to the nearest wholes, tenths, hundredths, or thousandth. It save time and helps to express long term into short term. Rounding is only applicable on Float and Double data types. When you round a number always remember the following points − If the last digit is less than 5(that is 0, 1, 2, 3, 4) then round the previous digit down. For ... Read More
This tutorial will discuss how to write a Swift program to sort elements in lexicographical order(Dictionary order). An arrangement of the words, characters or numbers in alphabetical order staring from A to Z is known as lexicographic order. It is also known as dictionary order because the searching of the words are same as we search in the real dictionary. In lexicographical order, the words whose first letter is same are arranged in the same group and in the group words are sorted according to their second letter and so on. To sort the given list of elements into lexicographic ... Read More
This tutorial will discuss how to write a Swift program to count the number of vowels and consonants in a sentence. An alphabet contains 26 letters out of which 5 are vowels and 21 are consonants. A, E, I, O, and U are known as vowels and B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, W, X, Y, Z are known as consonants. Below is a demonstration of the same − Input Suppose our given input is − Entered String I like momos Output The desired output would be − ... Read More
Metaprogramming in python is defined as the ability of a program to influence itself. It is achieved by using metaclass in python. Metaclasses in Python Metaclasses are an OOP concept present in all python code by default. Python provides the functionality to create custom metaclasses by using the keyword type. Type is a metaclass whose instances are classes. Any class created in python is an instance of type metaclass. The type() function can create classes dynamically as calling type() creates a new instance of type metaclass. Syntax Syntax to create a class using type() is given below − class ... Read More
This tutorial will discuss how to write a Swift program to compute quotient and remainder. In a division process, a number is divided by another number to get a resultant number. Or we can say that division is a process in which we divides larger number of group into small number of groups such that each group contain same number of elements. The four main terms of division are − Dividend − Dividend is a number which we divide. Divisor − Divisor is a number by which we divide Quotient − Quotient is the result obtained by the division. Remainder ... Read More
When an object is deleted or destroyed, a destructor is invoked. Before terminating an object, cleanup tasks like closing database connections or filehandles are completed using the destructor. The garbage collector in Python manages memory automatically. for instance, when an object is no longer relevant, it clears the memory. In Python, the destructor is entirely automatic and never called manually. In the following two scenarios, the destructor is called − When an object is no longer relevant or it goes out of scope The object's reference counter reaches zero. Using the __del__() method In Python, a destructor is ... Read More
Data hiding is also known as data encapsulation and it is the process of hiding the implementation of specific parts of the application from the user. Data hiding combines members of class thereby restricting direct access to the members of the class. Data hiding plays a major role in making an application secure and more robust Data hiding in Python Data hiding in python is a technique of preventing methods and variables of a class from being accessed directly outside of the class in which the methods and variables are initialized. Data hiding of essential member function prevents the end ... Read More
In this article, we will show you how to read and print the first N lines of a text file for the given N value using python. Assume we have taken a text file with the name ExampleTextFile.txt consisting of some random text. We will return the first N lines of a text file for the given N value. ExampleTextFile.txt Good Morning Tutorials Point This is Tutorials Point sample File Consisting of Specific abbreviated source codes in Python Seaborn Scala Imagination Summary and Explanation Welcome user Learn with a joy Algorithm (Steps) Following are the Algorithm/steps to be followed ... Read More