Category Archives: Basic Programs in Python

Find GCD By Euclidean Algorithm Python Program

Find GCD By Euclidean Algorithm – Write a Python program to find the greatest common divisor (GCD) of two numbers using the Euclidean algorithm. The Euclidean algorithm The Euclidean algorithm is a method for finding the greatest common divisor (GCD) of two integers. The algorithm is based on the principle that the GCD of two… Read More »

Loading

Python Program To Print Nth Fibonacci Series Term

Python Program To Print Nth Fibonacci Series Term – You can write a Python program to print the Nth Fibonacci term using a simple iterative approach. Here’s an example: Source Code def nth_fibonacci(n): if n <= 0: return “N should be a positive integer.” elif n == 1: return 0 elif n == 2: return… Read More »

Loading

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 »

Loading

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 »

Loading

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 »

Loading

Python Square Root Program

Python Square Root Program – Write a Python Program To find Square root of a number. Three Python programs to find square root of a number using Python. Code of Python Square Root Programs Program 1:Use Exponentiation Operator Exponentiation Operator ** in Python is used to raise the first operand/number to power of second number.… Read More »

Loading

Python GCD Recursive Function

Python GCD Recursive Function – Write a Python Program to find GCD of two numbers by recursion. Python GCD Recursive Function Python Program GCD of Two Numbers # Write a Python Program to find GCD # of two numbers using Recursion # define a recursive GCD function def recursive_gcd(a,b): if(b==0): return a else: return recursive_gcd(b,a%b)… Read More »

Loading