Python Articles

Page 713 of 855

Program to create grade calculator in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 3K+ Views

In academics, it is a common requirement to calculate student grades based on their assessment scores. In this article, we will create a Python program that assigns grades using a predefined grading criteria. Grading Criteria Below is the grading criteria used in our program − Score >= 90 : "O" (Outstanding) Score >= 80 : "A+" (Excellent) Score >= 70 : "A" (Very Good) Score >= 60 : "B+" (Good) Score >= 50 : "B" (Above Average) Score >= 40 : "C" (Average) Score < 40 : "F" (Fail) Program Structure Our ...

Read More

Print number with commas as 1000 separators in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 578 Views

Numbers with three or more digits often need to be displayed with commas for better readability, especially in accounting and finance applications. Python provides several methods to format numbers with commas as thousand separators. Using f-strings (Python 3.6+) The most modern approach uses f-string formatting with the comma specifier ? # Format integers with commas num1 = 1445 num2 = 140045 num3 = 5000000 print(f'{num1:, }') print(f'{num2:, }') print(f'{num3:, }') 1, 445 140, 045 5, 000, 000 Formatting Float Numbers For floating-point numbers, specify the decimal precision along with ...

Read More

Print first n distinct permutations of string using itertools in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 453 Views

When working with permutations of strings that contain duplicate characters, we often need to find only the distinct permutations. Python's itertools.permutations() generates all possible arrangements, including duplicates, so we need additional logic to filter unique results. Syntax from itertools import permutations def get_distinct_permutations(string, n): # Sort characters to group duplicates together sorted_chars = sorted(list(string)) # Generate all permutations all_perms = permutations(sorted_chars) # Use set to store ...

Read More

Prime or not in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 821 Views

Prime numbers play a central role in many applications like cryptography. So it is a necessity to check for prime numbers using Python programs in various applications. A prime number is a number which doesn't have any factors other than one and itself. Below we'll see programs that can find out if a given number is prime or not. Basic Approach We take the following approach to decide whether a number is prime or not ? Check if the number is positive or not. As only positive numbers can be prime numbers. We divide the number ...

Read More

Maximum length of consecutive 1's in a binary string in Python using Map function

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 505 Views

When working with binary strings, you may need to find the maximum length of consecutive 1's. Python provides several approaches using built-in functions like split() with map() and regular expressions. Using Split and Map The split() function divides a string by a delimiter. When we split by '0', we get segments of consecutive 1's. The map() function applies len() to each segment, and max() finds the longest one ? Example data = '11110000111110000011111010101010101011111111' def max_consecutive_ones(binary_string): return max(map(len, binary_string.split('0'))) result = max_consecutive_ones(data) print("Maximum Number of consecutive one's:", result) ...

Read More

Usage of Asterisks in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 354 Views

Python programming language uses both * and ** in different contexts. In this article, we will explore how these operators are used and their practical applications. As an Infix Operator When * is used as an infix operator, it performs mathematical multiplication on numbers. Let's see examples with integers, floats, and complex numbers ? # Integers x = 20 y = 10 z = x * y print(z) # Floats x1 = 2.5 y1 = 5.1 z1 = x1 * y1 print(z1) # Complex Numbers x2 = 4 + 5j y2 = 5 + ...

Read More

Statistical Thinking in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 453 Views

Statistical thinking is fundamental for machine learning and AI. Since Python is the language of choice for these technologies, we will explore how to write Python programs that incorporate statistical analysis. In this article, we will create graphs and charts using various Python modules to analyze data quickly and derive insights through visualization. Data Preparation We'll use a dataset containing information about various seeds. This dataset is available on Kaggle and has eight columns that we'll use to create different types of charts for comparing seed features. The program below loads the dataset and displays sample rows. ...

Read More

Predicting Customer Churn in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 686 Views

Customer churn refers to customers leaving a business. Predicting churn helps businesses identify at-risk customers and take preventive actions. This article demonstrates how to build a machine learning model to predict telecom customer churn using Python. Dataset Overview We'll use the Telecom Customer Churn dataset which contains customer information like demographics, services, and churn status. Let's load and examine the data ? import pandas as pd # Loading the Telco-Customer-Churn.csv dataset # Dataset available at: https://www.kaggle.com/blastchar/telco-customer-churn data = pd.read_csv('Telecom_customers.csv') print("Dataset shape:", data.shape) print("First few rows:") print(data.head()) The output shows the dataset structure ? ...

Read More

Fraud Detection in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 3K+ Views

Fraud detection is a critical application of machine learning where we analyze historical transaction data to predict whether a new transaction is fraudulent. In this tutorial, we'll build a fraud detection system using credit card transaction data, applying a decision tree classifier to identify suspicious transactions. Preparing the Data We start by loading and exploring our dataset to understand its structure and features. The credit card fraud dataset contains anonymized features (V1-V28) obtained through PCA transformation, along with Time, Amount, and Class columns ? import pandas as pd # Load the credit card dataset # ...

Read More

Fast XML parsing using Expat in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 2K+ Views

Python's xml.parsers.expat module provides fast XML parsing using the Expat library. It is a non-validating XML parser that creates an XML parser object and captures XML elements through various handler functions. This event-driven approach is memory-efficient and suitable for processing large XML files. How Expat Parser Works The Expat parser uses three main handler functions ? StartElementHandler − Called when an opening tag is encountered EndElementHandler − Called when a closing tag is encountered CharacterDataHandler − Called when character data between tags is found Example Here's how to parse XML data using Expat ...

Read More
Showing 7121–7130 of 8,549 articles
« Prev 1 711 712 713 714 715 855 Next »
Advertisements