# Category Archives: Python Programming Language

## Python Program Print Hollow Diamond Star Pattern

Python Program Print Hollow Diamond Star Pattern- # Number of rows row = 7 # this code will print upper part of hollow diamond pattern for i in range(1, row+1): for j in range(1,row-i+1): print(” “, end=””) for j in range(1, 2*i): if j==1 or j==2*i-1: print(“*”, end=””) else: print(” “, end=””) print() # now… Read More » ## Python Program Convert Gallons To Litres Using Function

Python Program Convert Gallons To Litres – To convert gallons to liters in Python, you can use the following simple program. The conversion factor is 1 US gallon = 3.78541 liters. This program defines a function gallons_to_liters that takes the number of gallons as input and returns the equivalent amount in liters. It then takes… Read More » ## Python Program Execution Time Calculator

Python Program Execution Time Calculator – You can calculate the execution time of a Python program using the time module. Here’s a simple Python program that demonstrates how to measure the execution time of a block of code: import time # Record the start time start_time = time.time() # Your code to be measured goes… Read More » ## Python Program Binary Search

Python Program Binary Search – In this program, a sorted list is given and a target item to be searched in the list.   Source Code of Python Binary Search Program binary_search(arr, target): left, right = 0, len(arr) – 1 while left ## Python Program Print Hollow Heart of Stars

Python Program Print Hollow Heart of Stars – This is a Python program that will print a Hollow Heart of stars.   Source Code n = 6 for row in range(n): for col in range(n+1): if (row == 0 and col % 3 != 0) or (row == 1 and col % 3 == 0)… Read More » ## Hollow Square of Stars Printing Python Program

Hollow Square of Stars Printing Python Program – This program will print a hollow square of stars in Python programming language. Here’s a Python program to print a hollow square: n = 5 for i in range(n): if i == 0 or i == n – 1: print(‘*’ * n) else: print(‘*’ + ‘ ‘… Read More » ## Print Inverted Pyramid of Stars in Python

Print Inverted Pyramid of Stars in Python – Write a Python program to display inverted pyramid of stars.   Source Code n = 5 for i in range(n, 0, -1): print(‘ ‘ * (n – i) + ‘*’ * (2 * i – 1)) ## Python Different Counts in String

Python Different Counts in String – Python program to count uppercase letters, lower case letters, vowels, consonants and spaces in the given string.   #Python program to count upper case letters, lower case letters #vowels, consonants and spaces in a string uppercase=0 lowercase=0 vowels=0 consonants=0 spaces=0 string=input(“Enter a String: “) for ch in string: if… Read More » ## Python Function Circle Area

Python Function Circle Area – Write a Python program to input radius of a circle. Calculate the area of the circle with the given radius. Source code for Python Program to find Area of Circle # Python Function Area of Circle # Define the function to find area of circle def area_of_circle(radius): if radius <… Read More » ## Python Program Check Positive Number

Python Program Check Positive Number – Write a Python program to input a number and check whether the given number is positive, negative or zero. Use Python if-elif-else construct. Python Program Check Positive, Negative or Zero Number # Python program to check a number # for positive, negative or zero num = int(input(‘Enter a number:… Read More » 