Found 10805 Articles for Python

Python Program to calculate the area of a Tetrahedron

Pavitra
Updated on 25-Sep-2019 12:37:59

273 Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statement −Given the side of a tetrahedron, we need to find a tetrahedron.A Tetrahedron is a geometric figure which looks like a pyramid with a triangular base. It is a solid object with four triangular faces, three on the sides, one on the bottom of the base and four vertices or corners.Here we frame an area function as shown below −Exampleimport math def areatetrahedron(side):    return (math.sqrt(3) * (side * side)) # Driver Code side = 20 print("Area of Tetrahedron = ", area_of_tetrahedron(side))OutputArea ... Read More

Python Implementing Web Scraping with Scrapy

Pavitra
Updated on 25-Sep-2019 12:04:21

133 Views

In this article, we will learn about the web scraping technique using the Scrappy module available in Python.What is web scraping?Web scraping is used to obtain/get the data from a website with the help of a crawler/scanner. Web scrapping comes handy to extract the data from a web page that doesn't offer the functionality of an API. In python, web scraping can be done by the help of various modules namely Beautiful Soup, Scrappy & lxml.Here we will discuss web scraping using the Scrappy module.For that, we first need to install Scrappy.Type in the terminal or command prompt>>> pip install ... Read More

Python Program for simple interest

Pavitra
Updated on 11-Sep-2019 13:21:02

1K+ Views

In this article, we will learn about the calculation of simple interest in Python 3.x. Or earlier.Simple interest is calculated by multiplying the daily interest rate by the principal amount by the number of days that elapse between the payments.Mathematically, Simple Interest = (P x T x R)/100 Where, P is the principal amount T is the time and R is the rateFor example, If P = 1000, R = 1, T = 2 Then SI=20.0 Now let’s see how we can implement a simple interest calculator in Python.Example Live DemoP = 1000 R = 1 T = 2 # simple ... Read More

Python Program for Selection Sort

Pavitra
Updated on 11-Sep-2019 13:18:05

2K+ Views

In this article, we will learn about the Selection sort and its implementation in Python 3.x. Or earlier.In the selection sort algorithm, an array is sorted by recursively finding the minimum element from the unsorted part and inserting it at the beginning. Two subarrays are formed during the execution of Selection sort on a given array.The subarray, which is already sortedThe subarray, which is unsorted.During every iteration of selection sort, the minimum element from the unsorted subarray is popped and inserted into the sorted subarray.Let’s see the visual representation of the algorithm −Now let’s see the implementation of the algorithm ... Read More

Python program for removing nth character from a string

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

121 Views

In this article, we will learn about the solution to the problem statement given below −Problem statement − We are given a string, we have to remove the ith indexed character from the given string and display it.In any string in Python, indexing always starts from 0. Suppose we have a string “tutorialspoint” then its indexing will be done as shown below −T u t o r i a l s p o i n t 0 1 2 3 4 5 6 7 8 9 10 11 12 13Now let’s see the Python script for ... Read More

Python Program for Product of unique prime factors of a number

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

905 Views

In this article, we will learn about the solution to the problem statement given below −Problem statement − Given a number n, we need to find the product of all of its unique prime factors available and return it.For example, Input: num = 11 Output: Product is 11 Explanation: Here, the input number is 11 having only 1 prime factor and it is 11. And hence their product is 11.Approach 1Using a for loop from i = 2 to n+1 check whether i is a factor of n & then check if i is the prime number itself, if yes ... Read More

Python Program for Print Number series without using any loop

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

513 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

156 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

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

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

400 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

Advertisements