Server Side Programming Articles

Page 280 of 2109

Program to find ex in an efficient way in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 172 Views

The mathematical constant e raised to the power x (ex) can be calculated efficiently using the Taylor series expansion without library functions. The formula for ex is: ex = 1 + x + x²/2! + x³/3! + x⁴/4! + ... For example, if x = 5, then e5 ≈ 148.4131 because e5 = 1 + 5 + (5²/2!) + (5³/3!) + ... = 148.4131... Algorithm To solve this efficiently, we follow these steps ? Initialize factorial = 1, result = 1, and numerator = x Set n = 20 (number of terms for precision) ...

Read More

Python program to find angle between mid-point and base of a right angled triangle

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 2K+ Views

When we have a right-angled triangle with sides AB and BC, we can find the angle between the midpoint M of the hypotenuse AC and the base BC using trigonometry. This angle can be calculated using the arctangent function. A B C M θ ...

Read More

Python program to find difference between two timestamps

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 3K+ Views

When working with timestamps in different timezones, you often need to calculate the time difference between them. Python's datetime library provides powerful tools to parse timestamp strings and compute differences accurately. The timestamp format "Day dd Mon yyyy hh:mm:ss +/-xxxx" includes timezone information, where +/-xxxx represents the offset from GMT (e.g., +0530 means 5 hours 30 minutes ahead of GMT). Understanding Format Specifiers The strptime() function uses format specifiers to parse timestamp strings − %a − Day in three letter format (Thu, Fri, etc.) %d − Day in numeric format (01-31) %b − Month in ...

Read More

Python program to split string into k distinct partitions

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 634 Views

When working with strings, we sometimes need to split them into equal-sized partitions and remove duplicate characters from each partition. This creates k distinct partitions where each partition contains unique characters only. Problem Statement Given a string s and a value k (where k is a factor of the string length), we need to: Split the string into n/k substrings of size k Remove duplicate characters from each substring Maintain the original character order within each partition For example, with s = "MMPQMMMRM" and k = 3, we get partitions ["MMP", "QMM", "MRM"] which ...

Read More

Python program to find score and name of winner of minion game

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 513 Views

The Minion Game is a string-based competition between two players where they create substrings based on whether they start with vowels or consonants. Let's explore how to determine the winner and their score. Game Rules The game follows these rules ? Both players have the same string s Amal creates substrings starting with vowels (A, E, I, O, U) Bimal creates substrings starting with consonants Each player scores 1 point for every occurrence of their substring in the original string The player with the highest total score wins Example Breakdown For the string ...

Read More

Program to update list items by their absolute values in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 292 Views

Sometimes we need to convert negative numbers in a list to their absolute values while keeping positive numbers unchanged. Python provides several approaches to update list items with their absolute values. Using map() with Lambda Function The map() function applies a lambda function to each element in the list ? def solve(nums): return list(map(lambda x: abs(x), nums)) nums = [5, -7, -6, 4, 6, -9, 3, -6, -2] result = solve(nums) print("Original list:", nums) print("Absolute values:", result) Original list: [5, -7, -6, 4, 6, -9, 3, -6, -2] ...

Read More

Program to find length of a list without using built-in length() function in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 839 Views

Finding the length of a list without using built-in functions like len() is a common programming exercise. We can achieve this using several creative approaches including loops, mapping, and recursive methods. So, if the input is like nums = [5, 7, 6, 4, 6, 9, 3, 6, 2], then the output will be 9. Method 1: Using map() and sum() We can map each element to 1 and then sum the results ? def find_length_map(nums): return sum(map(lambda x: 1, nums)) nums = [5, 7, 6, 4, 6, 9, 3, 6, ...

Read More

Program to find sum of odd elements from list in Python

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 26-Mar-2026 8K+ Views

In Python, you can find the sum of all odd elements in an existing List using one of the following ways: Using List Comprehension Using a Loop Using filter() Function Using List Comprehension The List Comprehension method allows us to create ...

Read More

Program to reverse a list by list slicing in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 322 Views

List slicing in Python provides a simple and efficient way to reverse a list using the slice notation [::-1]. This approach creates a new list with elements in reverse order without modifying the original list. Understanding List Slicing Syntax List slicing takes three parameters separated by colons: [start:end:step] start − Starting index (default: 0) end − Ending index (default: length of list) step − Step size (default: 1) For reversing, we use [::-1] where: Empty start and end means include entire list -1 step means move backwards through the list ...

Read More

Program to create a list with n elements from 1 to n in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 3K+ Views

Creating a list with n elements from 1 to n is a common task in Python. There are several efficient approaches using list comprehension, range() with list(), and other methods. So, if the input is like n = 5, then the output will be [1, 2, 3, 4, 5] Using List Comprehension List comprehension provides a concise way to create lists by iterating over a range ? def solve(n): return [i for i in range(1, n+1)] n = 5 result = solve(n) print(result) [1, 2, 3, 4, ...

Read More
Showing 2791–2800 of 21,090 articles
« Prev 1 278 279 280 281 282 2109 Next »
Advertisements