Programming Articles - Page 493 of 3363

Calculating profit or loss using Python

Vikram Chiluka
Updated on 23-Jan-2023 13:55:20

7K+ Views

In this article, we will learn a Python Program to calculate Profit Or Loss. The following are the different methods to accomplish this task − Using If Conditional Statements Using the abs() function. What are the selling price, cost price, and Profit and Loss? The price a consumer pays to purchase a product or a commodity is known as the selling price. It is a price that is higher than the cost price and also includes a portion of the profit. Cost price is the cost at which the seller buys the product or the commodity. He ... Read More

Breaking a Set into a list of sets using Python

Vikram Chiluka
Updated on 23-Jan-2023 12:48:43

581 Views

In this article, we will learn how to break a Set into a list of sets in Python. Assume we have taken an input set. We will now break this input set into a list of sets element-wise using the below-mentioned methods. Methods Used The following are the various methods used to accomplish this task − Using For Loop and append(), add() functions Using Python map() & lambda functions Using List Comprehension Method 1: Using For Loop and append(), add() Functions Algorithm (Steps) Following are the Algorithms/steps to be followed to perform the desired task. − Create ... Read More

Adding a data table to the figure using Python

Vikram Chiluka
Updated on 23-Jan-2023 12:45:48

2K+ Views

In this article, we will learn how to add a data table to the figure using Python. Although matplotlib is primarily a plotting library, it also assists us with minor tasks when making a chart, such as having a nice data table alongside our attractive visuals. It is critical to understand why we are adding a table to a plot. The primary goal of plotting data visually is to clarify the otherwise incomprehensible (or barely understandable) data values. Now we want to add the data back in. It is not advisable to just put a large table with values beneath ... Read More

Haskell Program to read an integer number from the user

Akhil Sharma
Updated on 23-Jan-2023 11:49:39

3K+ Views

This tutorial will help us to read an integer number from the user. The user is prompted to enter any integer number. Then the entered integer is displayed to the console. Method 1: Using read and getLine function This approach uses the read and getLine function to attempt to parse the input as an integer and display the integer number to the console. Algorithm Step 1 − main :: IO () is defining the main function. Step 2 − putStrLn "Enter an integer: " prints the message asking for the user input. Step 3 − input

Haskell Program to find the 1's complement of the given number

Akhil Sharma
Updated on 23-Jan-2023 11:37:24

445 Views

This tutorial will help us to find the 1's complement of the given number. The 1's complement of a binary number is found by inverting each bit of the number. A 1 becomes a 0, and a 0 becomes a 1. This is also known as the bitwise NOT operation. The 1's complement of a number can be useful in certain types of error-detecting and error-correcting Example:s, as well as in certain types of digital logic circuits. The most common use of 1's complement is in signed number representation where it's used to represent negative numbers. For example, if the ... Read More

Haskell Program to find the power of a number using library function

Akhil Sharma
Updated on 01-Mar-2023 10:02:52

294 Views

This tutorial will help us to find the power of a number using library function. The base value and the exponent value is passed as an argument that is used to find the exponent power of the base value passed. And the final output is displayed. For example, For base = 2 ; exponent = 3, it would return 8. Syntax power x y = product (replicate (fromInteger y) x) Product function computes a product of all elements in the list power x y = foldl (*) 1 (replicate (fromInteger y) x) Foldl takes the first item with ... Read More

Haskell Program to read the height of a person and the print person is taller, dwarf, or average height person

Akhil Sharma
Updated on 23-Jan-2023 11:31:38

181 Views

This tutorial will help us in reading the height of a person and printing if the person is taller, dwarf or average height person on being compared. The height value (in centimeters) is passed as argument to the function defined and then the height is being compared with the condition defined in Haskell. And the final output is displayed. Algorithm Step 1 − Program execution will be started from main function. The main() function has whole control of the program. Step 2 − Create user defined function to perform the task Step 3 − The if-else statement is defined ... Read More

Haskell Program to extract the last two digits from the given year

Akhil Sharma
Updated on 23-Jan-2023 11:16:52

515 Views

This tutorial will help us in extracting the last two digits from the given year. The year value is passed as an argument to the function defined and then the last two digits are extracted by using various methods in Haskell. And the final output is displayed. For example, For entered year = 2023, the last two digits = 23. Algorithm Step 1 − The Data.Char module is imported to use digitToInt function. Step 2 − The extractLastTwoDigits function is defined Step 3 − Program execution will be started from main function. The main() function has whole control of ... Read More

Haskell Program to read coordinate points and determine its quadrant

Akhil Sharma
Updated on 23-Jan-2023 11:14:11

313 Views

This tutorial will help us in reading the x and y coordinates and determine its quadrant. If both the coordinates are positive, the point lies in first quadrant; if x coordinate is positive and y coordinate is negative, the point lies in fourth quadrant ; if x coordinate is negative and y coordinate is positive, the point lies in second quadrant and if both the coordinates are negative, then point lies in third quadrant. Algorithm Step 1 − The quadrant function is defined using certain conditions on x and y coordinates. Step 2 − Program execution will be ... Read More

Haskell Program to calculate the volume and area of Sphere

Akhil Sharma
Updated on 23-Jan-2023 11:12:16

338 Views

This tutorial will help us in calculating the volume and area of Sphere. The volume of a sphere is a measure of the amount of space inside the sphere. And area involves the surface area of the sphere. Method 1: Using the User-defined Function In this method, we will see two examples where we have used user-defined function with different techniques. Algorithm Step 1 − The Text.Printf module is imported. Step 2 − The volume and area functions are defined on the basis of simple mathematical formula as volume r = (4.0 / 3.0) * pi * (r ^ ... Read More

Advertisements