Posts

Showing posts from April, 2021

How to make Fibonacci Series using recursion in Python.

Image
Fibonacci Series Q) What is a Fibonacci Series ? 0 1 1 2 3 5 8 13 21 34.... Explanation -  the 2 is found by adding the two numbers before it (1+1) the 3 is found by adding the two numbers before it (1+2), the 5 is (2+3), and so on! If you are interested to see the longer list - 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, ... Question - Given a number n, print n-th Fibonacci Number ? Explanation - We have to solve it through recursion. The program will start from Line no.   9 , it will take an input n (integer). (Let's take n= 5) Then the cursor will move to Line no. 10 for loop i.e for i in range ( 1,6 ). Loop will run 5 times storing value 1 2 3 4 5 in consecutive loop. First, it will store value 1 i.e. i=1, and when we print(fb(1)), the cursor will move to Line No. 1 ( where our function define). Then it will move to conditional

Arithmetic Operators in Python

Image
Arithmetic Operators in Python Arithmetic operators are used with numeric values to perform common mathematical operations Follows -  Addition ( +) = x+y  Subtraction ( - ) = x-y Multiplication ( * ) = x*y Division ( / ) = x/y Modulus ( % ) = x%y (Return remainder) Exponentiation ( ** ) = x**y (Return x^y) Floor Division ( // ) = x//y (Return quotient in integer ) So, let's see an example -  Code on Pydroid 3

if - else statements in Python

Image
If - else statements in Python Let's first have a look on Question So, in this question we get an input n  (integer). Now, in this question we have to use some Operator ( Logical ). Following 6 Logical operator- And all other operator will be discussed in Python on Android  Python  

print (Hello world) program in Python

Image
Hello World !! First program of every programmer print() statement -  The print() function prints the specified message to the screen, or other standard output device. The message can be a string, or any other object, the object will be converted into a string before written to the screen. Content and Questions from Hackerrank   Questions -  Output - single line of code