Category: Python Programming Examples

python tutorials and learn python

Created with Sketch.

Python Program to find sum of array

Python Program to find sum of array Given an array of integers, find sum of its elements. Examples : Input : arr[] = {1, 2, 3} Output : 6 1 + 2 + 3 = 6 Input : arr[] = {15, 12, 13, 10} Output : 50 # Python 3 code to find sum  #…
Read more

Python Program for Sum of squares of first n natural numbers

Python Program for Sum of squares of first n natural numbers Given a positive integer N. The task is to find 12 + 22 + 32 + ….. + N2. Examples: Input : N = 4 Output : 30 12 + 22 + 32 + 42 = 1 + 4 + 9 + 16 =…
Read more

Python Program for cube sum of first n natural numbers

Cube Sum of First 𝑛 Natural Numbers using Python In this extensive blog post, we’ll explore how to create a Python program to calculate the cube sum of the first 𝑛 natural numbers. The article will cover the algorithm involved, provide the Python code for implementation, and include examples with corresponding outputs. Understanding the Algorithm…
Read more

Python Program for How to check if a given number is the Fibonacci number?

Python Program for How to check if a given number is the Fibonacci number? Given a number \’n\’, how to check if n is a Fibonacci number. First few Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 141, .. Examples : Input : 8 Output : Yes Input…
Read more

Python Program for n\’th multiple of a number in Fibonacci Series

Python Program for Finding the n’th Multiple in Fibonacci Series Introduction In this blog post, we will explore a Python program to find the n’th multiple of a given number in the Fibonacci series. The Fibonacci series is a sequence of numbers where each number is the sum of the two preceding ones. By extending…
Read more

Program to print ASCII Value of a character

perm_identityUser Actions Program to print ASCII Value of a character Given a character, we need to print its ASCII value in C/C++/Java/Python.   Examples : Input : a Output : 97 Input : D Output : 68 Here are few methods in different programming languages to print ASCII value of a given character : Python…
Read more

Python Program for Fibonacci numbers

Python Program for Fibonacci Numbers Introduction Fibonacci numbers are a series of numbers in which each number (Fibonacci number) is the sum of the two preceding ones. The sequence starts with 0 and 1, and the subsequent numbers in the sequence are obtained by adding the two numbers just before it. In mathematical terms, the…
Read more

Python Program for n-th Fibonacci number

Python Program for n-th Fibonacci number In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation Fn = Fn-1 + Fn-2 with seed values F0 = 0 and F1 = 1. Method 1 ( Use recursion ) : # Function for nth Fibonacci number   def Fibonacci(n):     if n<0:         print(“Incorrect…
Read more

Python program to check whether a number is Prime or not

Python program to check whether a number is Prime or not Given a positive integer N. The task is to write a Python program to check if the number is prime or not. Definition: A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. The…
Read more

Python program to print all Prime numbers in an Interval

Python program to print all Prime numbers in an Interval Given two positive integer start and end. The task is to write a Python program toprint all Prime numbers in an Interval. Definition: A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. The first…
Read more