Print Number Series Without Using Any Loop in Python

Pavitra
Updated on 11-Sep-2019 13:04:11

725 Views

In this article, we will learn about the solution to the problem statement given below −Problem statement − Given Two number N and K, our problem is to subtract a number K from N until number(N) is greater than zero(0), once the N becomes negative or zero then we start adding K to it until that number become the original number(N).For example, N = 10 K = 4 Output will be: 10 6 2 -2 2 6 10Algorithm1. we call the function again and again until N is greater than zero (in every function    call we subtract K ... Read More

Python Program for N-th Fibonacci Number

Pavitra
Updated on 11-Sep-2019 12:15:41

1K+ Views

In this article, we will compute the nth Fibonacci number.A Fibonacci number is defined by the recurrence relation given below −Fn = Fn-1 + Fn-2With F0= 0 and F1 = 1.First, few Fibonacci numbers are0,1,1,2,3,5,8,13,..................We can compute the Fibonacci numbers using the method of recursion and dynamic programming.Now let’s see the implementation in the form of Python scriptApproach 1: Recursion MethodExample Live Demo#recursive approach def Fibonacci(n):    if n

Python Program for Nth Catalan Number

Pavitra
Updated on 11-Sep-2019 12:10:47

532 Views

In this article, we will learn about calculating the nth Catalan number.Catalan numbers are a sequence of natural numbers that are defined by the recursive formula −$$C_{0}= 1\:and\:C_{n+1}=\displaystyle\sum\limits_{i=0}^n C_{i}C_{n-i} for \:n\geq0;$$The first few Catalan numbers for n = 0, 1, 2, 3, … are 1, 1, 2, 5, 14, 42, 132,429,...................Catalan numbers can be obtained both by recursion and dynamic programming. So let’s see their implementation.Approach 1: Recursion MethodExample Live Demo# A recursive solution def catalan(n):    #negative value    if n

Check If a Given Number Is a Fibonacci Number in Python

Pavitra
Updated on 11-Sep-2019 11:56:56

584 Views

In this article, we will learn about the solution to the problem statement given below −Problem statementGiven a number n, check whether n is a Fibonacci number or notWe all are aware that the nth Fibonacci number is the sum of the previous two Fibonacci numbers. But they also offer an interesting relation other than the recurrence relation.A number is Fibonacci in nature if and only if (5*n2 + 4) or (5*n2 – 4) is a perfect square.We will use this property to check whether a number is Fibonacci or not.Now let’s see the implementation of the Python script −Example Live ... Read More

GCD of More Than Two or Array Numbers in Python

Pavitra
Updated on 11-Sep-2019 11:53:55

1K+ Views

In this article, we will learn about the solution to the problem statement given below −Problem statement − We will be given an array of number and we need to find the greatest common divisor.If we need to find gcd of more than two numbers, gcd is equal to the product of the prime factors common to all the numbers provided as arguments. It can also be calculated by repeatedly taking the GCDs of pairs of numbers of arguments.Here we will be implementing the latter approachSo now, let’s see the implementationExample Live Demodef findgcd(x, y):    while(y):       x, ... Read More

Focal Length of a Spherical Mirror in Python

Pavitra
Updated on 11-Sep-2019 11:51:14

420 Views

In this article, we will learn about the solution to the problem statement given below −Problem statementWe will be given the radius of curvature of the spherical mirror and we have to find the focal length of the same.The focal length is the distance between the centre of curvature of the mirror to the principal foci. In order to determine the focal length of a spherical mirror firstly, we should know the radius of curvature of that mirror. The distance from the vertex of the mirror to the centre of curvature is called the radius of curvature.Mathematically −For concave mirror: ... Read More

Use Facebook SDK in Android Studio

Azhar
Updated on 11-Sep-2019 11:50:10

258 Views

This example demonstrates about How to use facebook SDK in Android studioDownload the SDK from the Maven Central Repository:buildscript { repositories { mavenCentral()}}Compile the latest version of the SDK:dependencies {    implementation 'com.facebook.android:facebook-android-sdk:[5,6)' }Click here to download the project code.

Find Vertex, Focus and Directrix of a Parabola in Python

Pavitra
Updated on 11-Sep-2019 11:48:11

1K+ Views

In this article, we will learn about the solution to the problem statement given below −Problem statementThe standard form of a parabola equation is y=ax^2+bx+c. Input the values of a, b and c, our task is to find the coordinates of the vertex, focus and the equation of the directrix.The vertex of a parabola is the coordinate from which it takes the sharpest turn whereas y=a is the straight-line used to generate the curve.A directrix a fixed-line used in describing a curve or surface.Now let’s see the implementation −Example Live Demodef findparabola(a, b, c):    print ("Vertex: (" , (-b / ... Read More

Create Android Facebook Key Hash

Azhar
Updated on 11-Sep-2019 11:45:46

1K+ Views

This example demonstrates about How to create Android Facebook Key HashGenerating a Development Key HashMac OS:- Execute below command in terminal keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64Windows:- Execute below command in command prompt keytool -exportcert -alias androiddebugkey -keystore "C:\Users\USERNAME\.android\debug.keystore" | "PATH_TO_OPENSSL_LIBRARY\bin\openssl" sha1 -binary | "PATH_TO_OPENSSL_LIBRARY\bin\openssl" base64Generating a Release Key Hashkeytool -exportcert -alias YOUR_RELEASE_KEY_ALIAS -keystore YOUR_RELEASE_KEY_PATH | openssl sha1 -binary | openssl base64Click here to download the project code.

Find the Perimeter of a Cylinder in Python

Pavitra
Updated on 11-Sep-2019 11:45:20

133 Views

In this article, we will learn about the solution to the problem statement given below −Problem statement − Input diameter and height, find the perimeter of a cylinderPerimeter is nothing but the side view of a cylinder i.e. a rectangleTherefore Perimeter= 2 * ( h + d )here d is the diameter of the cylinderh is the height of the cylinderNow let’s see the implementationExample Live Demo# Function to calculate the perimeter of a cylinder def perimeter( diameter, height ) :    return 2 * ( diameter + height ) # main diameter = 5 ; height = 10 ; print ... Read More

Advertisements