Blog

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 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

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 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