Python Articles

Page 695 of 855

Basic calculator program using Python program

Niharikaa Aitam
Niharikaa Aitam
Updated on 25-Mar-2026 2K+ Views

In this tutorial, we are going to build a basic calculator in Python. A calculator provides multiple arithmetic operations to users, allowing them to select one option and perform the respective calculation. Following are the arithmetic operations that we can perform using a basic calculator − Addition Subtraction Multiplication Division Steps in Developing the Basic Calculator Following are the steps involved in creating a basic calculator in Python − Defining Arithmetic Functions First, we define all the arithmetic operations that can be performed by using a basic calculator ? def ...

Read More

Check if both halves of the string have same set of characters in Python

Niharikaa Aitam
Niharikaa Aitam
Updated on 25-Mar-2026 412 Views

In Python, a string is one of the data structures that is a sequence of characters enclosed within single quotes '' or double quotes "". It is immutable, i.e., once a string is created, it cannot be changed. When we want to check if both halves of the string have the same set of characters in Python, we can follow the steps below − First, based on the length of the string, we have to split the string into two halves. Next, convert each half into a set of characters using ...

Read More

Check for balanced parentheses in Python

Akshitha Mote
Akshitha Mote
Updated on 25-Mar-2026 1K+ Views

In this article, we will solve the problem of checking balanced parentheses. A string has balanced parentheses when every opening bracket has a corresponding closing bracket in the correct order. The following are the conditions for balanced parentheses − Every opening parenthesis has a corresponding closing parentheses. Parentheses should be closed in the correct order. For example, "{[()]}" is a balanced parenthesis. Consider the same example with different arrangement "{([})]" which is unbalanced parentheses. Using List and For Loop The stack-based approach uses a list to ...

Read More

Twitter Sentiment Analysis using Python Program

Pavitra
Pavitra
Updated on 25-Mar-2026 571 Views

Twitter sentiment analysis allows us to analyze public opinions and emotions from tweets using Python. We'll use the Twitter API to fetch tweets and TextBlob library to analyze their sentiment polarity. Twitter API Python Script TextBlob ...

Read More

Python program to print odd numbers in a list

Pavitra
Pavitra
Updated on 25-Mar-2026 3K+ Views

In this article, we will learn different approaches to find and print odd numbers from a list. An odd number is any integer that is not divisible by 2, meaning when divided by 2, it leaves a remainder of 1. Problem Statement Given a list of integers as input, we need to display all odd numbers present in the list. We will explore three different approaches to solve this problem efficiently. Using For Loop The most straightforward approach is to iterate through each number and check if it's odd using the modulo operator ? ...

Read More

Python Program to Print Numbers in an Interval

Pavitra
Pavitra
Updated on 25-Mar-2026 576 Views

In this article, we will learn how to print all numbers within a given interval using Python. We'll explore different approaches including printing all numbers, only even numbers, only odd numbers, and prime numbers in a range. Problem Statement Given a starting and ending range of an interval, we need to print all the numbers (or specific types of numbers) within that interval. Method 1: Print All Numbers in an Interval The simplest approach is to use a for loop with range() function to iterate through all numbers ? start = 5 end = ...

Read More

Python program to print even numbers in a list

Harshit Sachan
Harshit Sachan
Updated on 25-Mar-2026 13K+ Views

Python lists are fundamental data structures that store collections of items. Finding even numbers in a list is a common programming task with multiple efficient approaches. A number is even if it divides by 2 with no remainder. We will explore several methods to print even numbers from a list, each with different advantages ? Using Modulo Operator The modulo operator (%) returns the remainder when dividing two numbers. For even numbers, x % 2 == 0 will be true. Example def print_evens(numbers): for num in numbers: ...

Read More

Python program to print even length words in a string

Harshit Sachan
Harshit Sachan
Updated on 25-Mar-2026 6K+ Views

In Python, you can find and print all words in a string that have even length (divisible by 2). This is useful for text processing tasks where you need to filter words based on their character count. For example, in the string "A big cube was found inside the box", the words "cube" (length 4) and "inside" (length 6) have even lengths. Basic Approach The simplest method involves splitting the string into words and checking each word's length ? def print_even_length_words(text): # Split the string into individual words ...

Read More

Python program to find the most occurring character and its count

Pavitra
Pavitra
Updated on 25-Mar-2026 538 Views

In this article, we will learn how to find the most occurring character in a string and count its occurrences using Python's Counter class. Problem Statement Given an input string, we need to find the character that appears most frequently and return both the character and its count. Approach Create a dictionary using Counter method having characters as keys and their frequencies as values. Find the maximum occurrence count and get the corresponding character. Using Counter from collections The Counter class provides an easy way to count character frequencies ? ...

Read More

Python program to find the highest 3 values in a dictionary

Pavitra
Pavitra
Updated on 25-Mar-2026 3K+ Views

In this article, we will learn how to find the highest 3 values in a dictionary using different Python approaches. Problem Statement Given a dictionary, we need to find the three highest values and display them along with their corresponding keys. Using collections.Counter The Counter class provides a most_common() method that returns the n most common elements and their counts ? from collections import Counter # Initial Dictionary my_dict = {'a': 3, 'b': 4, 'c': 6, 'd': 5, 'e': 21} counter = Counter(my_dict) # Finding 3 highest values highest = counter.most_common(3) ...

Read More
Showing 6941–6950 of 8,549 articles
« Prev 1 693 694 695 696 697 855 Next »
Advertisements