Saba Hilal

Saba Hilal

54 Articles Published

Articles by Saba Hilal

Page 2 of 6

Python Program to Find Numbers Divisible by 7 and Multiple of 5 in a Given Range

Saba Hilal
Saba Hilal
Updated on 27-Mar-2026 2K+ Views

Finding numbers divisible by 7 and multiples of 5 within a range is a common programming problem. Python provides several approaches: using the modulo operator, iterative addition, and multiplication methods. Each approach has different performance characteristics and use cases. Method 1: Using Modulo Operator The most straightforward approach uses the modulo operator (%) to check divisibility. A number is divisible by 7 if number % 7 == 0, and a multiple of 5 if number % 5 == 0. Algorithm Step 1 − Define the range with lower and upper bounds. Step 2 − Iterate through ...

Read More

Python program to find the string weight

Saba Hilal
Saba Hilal
Updated on 27-Mar-2026 956 Views

In this article, we will calculate the total weight of a string by assigning numeric values to each character. The weight system is: a=1, b=2, c=3, and so on up to z=26. We'll explore two different approaches to find the string weight. Method 1: Direct Character Weight Addition This approach iterates through each character in the string and adds its corresponding weight to a running total. Algorithm Step 1 − Create a reference string with space and all lowercase letters. Step 2 − Use the index() function to get weight values (space = 0, a = ...

Read More

How to load and save 3D Numpy Array file using savetxt() and loadtxt() functions?

Saba Hilal
Saba Hilal
Updated on 27-Mar-2026 5K+ Views

When working with 3D NumPy arrays, savetxt() and loadtxt() functions cannot directly handle them since they expect 2D arrays. To save and load 3D arrays, you need to reshape them to 2D format first, then reshape back to 3D after loading. The Problem with 3D Arrays Using savetxt() or loadtxt() with 3D arrays directly throws an error: ValueError: Expected 1D or 2D array, got 3D array instead Solution: Reshape Before Saving and After Loading The solution involves three steps: Reshape 3D array to 2D before saving Save/load using savetxt()/loadtxt() Reshape back ...

Read More

How to lowercase the column names in Pandas dataframe?

Saba Hilal
Saba Hilal
Updated on 27-Mar-2026 6K+ Views

In this article, you'll learn how to convert column names and values to lowercase in a Pandas DataFrame. We'll explore three different methods: str.lower(), map(str.lower), and apply(lambda) functions. Creating a Sample DataFrame Let's start by creating a sample DataFrame to demonstrate the methods ? import pandas as pd # Create sample restaurant data data = { 'Restaurant Name': ['Pizza Palace', 'Burger King', 'Sushi Bar'], 'Rating Color': ['Green', 'Yellow', 'Red'], 'Rating Text': ['Excellent', 'Good', 'Average'] } df = pd.DataFrame(data) print("Original DataFrame:") print(df) ...

Read More

How to load a TSV file into a Pandas Dataframe?

Saba Hilal
Saba Hilal
Updated on 27-Mar-2026 5K+ Views

A TSV (Tab Separated Values) file is a text format where data columns are separated by tabs. Pandas provides two main methods to load TSV files into DataFrames: read_table() with delimiter='\t' and read_csv() with sep='\t'. Method 1: Using read_table() with delimiter='\t' The read_table() function is specifically designed for reading delimited text files ? import pandas as pd # Create a sample TSV data for demonstration tsv_data = """Name Age City Salary John 25 New York 50000 Alice 30 London 60000 Bob 28 Paris 55000 Carol 32 Tokyo 65000""" # Save sample data to a TSV file with open('sample.tsv', 'w') as f: f.write(tsv_data) # Load ...

Read More

How to Locate Elements using Selenium Python?

Saba Hilal
Saba Hilal
Updated on 27-Mar-2026 1K+ Views

Selenium is a powerful web automation tool that can be used with Python to locate and extract elements from web pages. This is particularly useful for web scraping, testing, and automating browser interactions. In this tutorial, we'll explore different methods to locate HTML elements using Selenium with Python. Setting Up Selenium Before locating elements, you need to set up Selenium with a WebDriver. Here's a basic setup ? from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.chrome.service import Service import time # Setup Chrome driver driver = webdriver.Chrome() driver.get("https://example.com") time.sleep(2) # Always close ...

Read More

How to iterate through a nested List in Python?

Saba Hilal
Saba Hilal
Updated on 27-Mar-2026 6K+ Views

A nested list in Python is a list that contains other lists as elements. Iterating through nested lists requires different approaches depending on the structure and your specific needs. What is a Nested List? Here are common examples of nested lists ? # List with mixed data types people = [["Alice", 25, ["New York", "NY"]], ["Bob", 30, ["Los Angeles", "CA"]], ["Carol", 28, ["Chicago", "IL"]]] # 3-dimensional nested list matrix = [ ...

Read More

How to invert the elements of a boolean array in Python?

Saba Hilal
Saba Hilal
Updated on 27-Mar-2026 1K+ Views

Boolean array inversion is a common operation when working with data that contains True/False values. Python offers several approaches to invert boolean arrays using NumPy functions like np.invert(), the bitwise operator ~, or np.logical_not(). Using NumPy's invert() Function The np.invert() function performs bitwise NOT operation on boolean arrays ? import numpy as np # Create a boolean array covid_negative = np.array([True, False, True, False, True]) print("Original array:", covid_negative) # Invert using np.invert() covid_positive = np.invert(covid_negative) print("Inverted array:", covid_positive) Original array: [ True False True False True] Inverted array: [False ...

Read More

How to Make a Bell Curve in Python?

Saba Hilal
Saba Hilal
Updated on 27-Mar-2026 2K+ Views

A bell curve (normal distribution) is a fundamental concept in statistics that appears when we plot many random observations. Python's Plotly library provides excellent tools for creating these visualizations. This article demonstrates three practical methods to create bell curves using different datasets. Understanding Bell Curves The normal distribution emerges naturally when averaging many observations. For example, rolling two dice and summing their values creates a bell-shaped pattern — the sum of 7 occurs most frequently, while extreme values (2 or 12) are rare. Example 1: Bell Curve from Dice Roll Simulation Let's simulate 2000 dice rolls ...

Read More

How to make a display in a horizontal row?

Saba Hilal
Saba Hilal
Updated on 16-Mar-2026 1K+ Views

Displaying HTML elements in a horizontal row is a common layout requirement in web development. There are several CSS techniques to achieve this, including display: inline, display: inline-block, display: flex, and using HTML table structures. This article demonstrates three different approaches to create horizontal layouts. CSS Display Properties for Horizontal Layout The most common CSS properties for horizontal arrangement are − display: inline − Elements flow horizontally but cannot have width/height set display: inline-block − Elements flow horizontally and can have dimensions display: flex − Modern flexible layout method with powerful alignment options HTML tables − ...

Read More
Showing 11–20 of 54 articles
Advertisements