Month: January 2021

Python Examples for Beginners: Python Code to Find Factorial of Number Using Recursion

(Python Tutorials for Citizen Data Scientist) Python Program to Find Factorial of Number Using Recursion In this program, you’ll learn to find the factorial of a number using recursive function. The factorial of a number is the product of all the integers from 1 to that number. For example, the factorial of 6 is 1*2*3*4*5*6 = …

Python Examples for Beginners: Python Code to Find Sum of Natural Numbers Using Recursion

(Python Tutorials for Citizen Data Scientist) Python Code to Find Sum of Natural Numbers Using Recursion In this program, you’ll learn to find the sum of natural numbers using recursive function. In the program below, we’ve used a recursive function recur_sum() to compute the sum up to the given number. Source Code # Python program to find …

Python Examples for Beginners: Python Code to Display Fibonacci Sequence Using Recursion

(Python Tutorials for Citizen Data Scientist) Python Program to Display Fibonacci Sequence Using Recursion In this program, you’ll learn to display Fibonacci sequence using a recursive function. A Fibonacci sequence is the integer sequence of 0, 1, 1, 2, 3, 5, 8…. The first two terms are 0 and 1. All other terms are obtained …

Python Examples for Beginners: Python Code to Display Calendar

(Python Tutorials for Citizen Data Scientist) Python Code to Display Calendar Python has a built-in function, calendar to work with date related tasks. You will learn to display the calendar of a given date in this example. In the program below, we import the calendar module. The built-in function month() inside the module takes in the year and the …

Python Examples for Beginners: Python Code to Shuffle Deck of Cards

(Python Tutorials for Citizen Data Scientist) Python Code to Shuffle Deck of Cards In this program, you’ll learn to shuffle a deck of cards using random module. Source Code # Python program to shuffle a deck of card # importing modules import itertools, random # make a deck of cards deck = list(itertools.product(range(1,14),[‘Spade’,’Heart’,’Diamond’,’Club’])) # shuffle …

Python Examples for Beginners: Python Code to Make a Simple Calculator

(Python Tutorials for Citizen Data Scientist) Python Code to Make a Simple Calculator In this example you will learn to create a simple calculator that can add, subtract, multiply or divide depending upon the input from the user. Example: Simple Calculator by Using Functions # Program make a simple calculator # This function adds two …

Python Examples for Beginners: Python Code to Find the Factors of a Number

(Python Tutorials for Citizen Data Scientist) Python Code to Find the Factors of a Number In this program, you’ll learn to find the factors of a number using the for loop. Source Code # Python Program to find the factors of a number # This function computes the factor of the argument passed def print_factors(x): …

Python Examples for Beginners: Python Code to Find LCM

(Python Tutorials for Citizen Data Scientist) Python Code to Find LCM In this program, you’ll learn to find the LCM of two numbers and display it. The least common multiple (L.C.M.) of two numbers is the smallest positive integer that is perfectly divisible by the two given numbers. For example, the L.C.M. of 12 and …

Python Examples for Beginners: Python Code to Find HCF or GCD

(Python Tutorials for Citizen Data Scientist) Python Program to Find HCF or GCD In this example, you will learn to find the GCD of two numbers using two different methods: function and loops and, Euclidean algorithm The highest common factor (H.C.F) or greatest common divisor (G.C.D) of two numbers is the largest positive integer that …