Python

Python Examples for Beginners: Python Code to Add Two Numbers

Hits: 10 (Python Tutorials for Citizen Data Scientist) Python Code to Convert Decimal to Binary, Octal and Hexadecimal In this program, you’ll learn to convert decimal to binary, octal and hexadecimal, and display it. The decimal system is the most widely used number system. However, computers only understand binary. Binary, octal and hexadecimal number systems …

Python Examples for Beginners: Python Code to Find Numbers Divisible by Another Number

Hits: 7 (Python Tutorials for Citizen Data Scientist) Python Program to Find Numbers Divisible by Another Number In this program, you’ll learn to find the numbers divisible by another number and display it.   In the program below, we have used anonymous (lambda) function inside the filter() built-in function to find all the numbers divisible by 13 …

Python Examples for Beginners: Python Code To Display Powers of 2 Using Anonymous Function

Hits: 9 (Python Tutorials for Citizen Data Scientist) Python Code To Display Powers of 2 Using Anonymous Function In this program, you’ll learn to display powers of the integer 2 using Python anonymous function. In the program below, we have used an anonymous (lambda) function inside the map() built-in function to find the powers of 2. Source …

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

Hits: 48 (Python Tutorials for Citizen Data Scientist) Python Code to Find the Sum of Natural Numbers In this program, you’ll learn to find the sum of n natural numbers using while loop and display it. In the program below, we’ve used an if…else statement in combination with a while loop to calculate the sum of natural …

Python Examples for Beginners: Python Code to Print the Fibonacci sequence

Hits: 14 (Python Tutorials for Citizen Data Scientist) Python Code to Print the Fibonacci sequence In this program, you’ll learn to print the Fibonacci sequence using while loop. 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 …

Python Examples for Beginners: Python Code to Display the multiplication Table

Hits: 20 (Python Tutorials for Citizen Data Scientist) Python Program to Display the multiplication Table This program displays the multiplication table of variable num (from 1 to 10). In the program below, we have used the for loop to display the multiplication table of 12. Source Code # Multiplication table (from 1 to 10) in …

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

Hits: 15 (Python Tutorials for Citizen Data Scientist) Python Code to Find the Factorial of a Number In this article, you’ll learn to find the factorial of a number and display it. The factorial of a number is the product of all the integers from 1 to that number. For example, the factorial of 6 …

Python Examples for Beginners: Python Code to Check Prime Number

Hits: 21 (Python Tutorials for Citizen Data Scientist) Python Code to Check Prime Number Example to check whether an integer is a prime number or not using for loop and if…else statement. If the number is not prime, it’s explained in output why it is not a prime number. A positive integer greater than 1 …

Python Examples for Beginners: Python Code to Find the Largest Among Three Numbers

Hits: 36 (Python Tutorials for Citizen Data Scientist) Python Code to Find the Largest Among Three Numbers In this program, you’ll learn to find the largest among three numbers using if else and display it. In the program below, the three numbers are stored in num1, num2 and num3 respectively. We’ve used the if…elif…else ladder to find the largest among the three …

Python Examples for Beginners: Python Code to Check Leap Year

Hits: 21 (Python Tutorials for Citizen Data Scientist) Python Program to Check Leap Year In this program, you will learn to check whether a year is leap year or not. We will use nested if…else to solve this problem. A leap year is exactly divisible by 4 except for century years (years ending with 00). …

Python Examples for Beginners: Python Code to Check if a Number is Odd or Even

Hits: 35 (Python Tutorials for Citizen Data Scientist) Python Program to Check if a Number is Odd or Even In this example, you will learn to check whether a number entered by the user is even or odd. A number is even if it is perfectly divisible by 2. When the number is divided by …

Python Examples for Beginners: Python Code to Check if a Number is Positive, Negative or Zero

Hits: 18 (Python Tutorials for Citizen Data Scientist) Python Program to Check if a Number is Positive, Negative or Zero In this example, you will learn to check whether a number entered by the user is positive, negative or zero. This problem is solved using if…elif…else and nested if…else statement. Source Code: Using if…elif…else num …

Python Examples for Beginners: Python Code to Convert Celsius To Fahrenheit

Hits: 27 (Python Tutorials for Citizen Data Scientist) Python Program to Convert Celsius To Fahrenheit In this program, you’ll learn to convert Celsuis to Fahrenheit and display it. In the program below, we take a temperature in degree Celsius and convert it into degree Fahrenheit. They are related by the formula: celsius * 1.8 = …

Python Examples for Beginners: Python Code to Convert Kilometers to Miles

Hits: 13 (Python Tutorials for Citizen Data Scientist) Python Code to Convert Kilometers to Miles In this example, we’ll learn to convert kilometers to miles and display it. Example: Kilometers to Miles # Taking kilometers input from the user kilometers = float(input(“Enter value in kilometers: “)) # conversion factor conv_fac = 0.621371 # calculate miles …

Python Examples for Beginners: Python Code to Generate a Random Number

Hits: 10 (Python Tutorials for Citizen Data Scientist) Python Program to Generate a Random Number In this example, you will learn to generate a random number in Python. To generate random number in Python, randint() function is used. This function is defined in random module. Source Code # Program to generate a random number between 0 and 9 …