Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Nilesh Kumar
5 articles
How to Produce K evenly spaced float values in Python?
This article focuses on how to produce K evenly spaced float values in Python. Evenly spaced values are commonly used in scientific computing, data visualization, and mathematical operations where uniform data distribution is essential for accurate analysis. Python provides multiple approaches to generate evenly spaced float values. We'll explore two main methods: using loops with manual calculation and using NumPy's linspace() function. Method 1: Using Manual Calculation with Loops This approach calculates the interval between values manually and uses a loop to generate the sequence ? def evenly_spaced_manual(start, end, count): result ...
Read MoreHow to Print a Heart Pattern Using Python?
Creating visual patterns with code is both educational and fun. In this article, we'll learn how to print a heart pattern using Python, which demonstrates loop control, conditional logic, and coordinate-based pattern generation. Understanding the Range Function The heart pattern uses nested loops with the range() function ? range(start, stop, step) Parameters: start − Starting position (optional, default is 0) stop − Ending position (required) step − Increment value (optional, default is 1) Heart Pattern Algorithm The heart pattern is created by dividing it into two main parts: Upper ...
Read MoreRandom Replacement of words using Python
Random word replacement is a text manipulation technique where we randomly select a word from input text and replace it with a randomly chosen word from a predefined list. This process introduces variation and generates different text versions, useful for content generation, testing, and creative writing. Python provides excellent tools for implementing random word replacement through the random module, which helps generate random indices for selecting words from text and replacement lists. Syntax The key functions used for random word replacement are ? random.randint(start, stop) Returns a random integer from the specified range. ...
Read MorePython - Product and Inter Summation dictionary values
In Python, dictionaries store key-value pairs where we can perform mathematical operations on the values. This article demonstrates how to calculate the sum and product of dictionary values using the values() method and loops. Syntax The primary method used is ? dictionary.values() The values() method returns a view object containing all dictionary values. It takes no arguments and allows iteration through values without accessing keys. Sum of Dictionary Values To calculate the sum, we initialize a variable to 0 and add each dictionary value ? def calculate_sum(dictionary): ...
Read MoreHow to Print the Last Word in a sentence using Python?
Extracting the last word from a sentence is a common text processing task in Python. This can be accomplished using the split() method to break the sentence into words and accessing the last element. Using split() Method The split() method divides a string into a list of words, making it easy to access the last word using negative indexing. Syntax string.split(separator, maxsplit) Parameters: separator − Optional. Specifies the delimiter (default is whitespace) maxsplit − Optional. Maximum number of splits (default is -1 for all occurrences) Example def print_last_word(sentence): ...
Read More