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: 19 (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: 19 (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 …

Python Examples for Beginners: Python Code to Swap Two Variables

Hits: 15 (Python Tutorials for Citizen Data Scientist) Python Code to Swap Two Variables In this example, you will learn to swap two variables by using a temporary variable and, without using temporary variable. Source Code: Using a temporary variable # Python program to swap two variables x = 5 y = 10 # To …

Python Examples for Beginners: Python Code to Solve Quadratic Equation

Hits: 17 (Python Tutorials for Citizen Data Scientist) Python Program to Solve Quadratic Equation This program computes roots of a quadratic equation when coefficients a, b and c are known. The standard form of a quadratic equation is: ax2 + bx + c = 0, where a, b and c are real numbers and a …

Python Examples for Beginners: Python Code to Calculate the Area of a Triangle

Hits: 8 (Python Tutorials for Citizen Data Scientist) Python Program to Calculate the Area of a Triangle In this program, you’ll learn to calculate the area of a triangle and display it. If a, b and c are three sides of a triangle. Then, s = (a+b+c)/2 area = √(s(s-a)*(s-b)*(s-c)) Source Code # Python Program to find the area of …

Python Examples for Beginners: Python Code to Find the Square Root

Hits: 8 (Python Tutorials for Citizen Data Scientist) Python Program to Find the Square Root In this program, you’ll learn to find the square root of a number using exponent operator and cmath module. Example: For positive numbers # Python Program to calculate the square root # Note: change this value for a different result …

Python Examples for Beginners: Python Code to Add Two Numbers

Hits: 19 (Python Tutorials for Citizen Data Scientist) Python Program to Add Two Numbers In this program, you will learn to add two numbers and display it using print() function. In the program below, we’ve used the + operator to add two numbers. Example 1: Add Two Numbers # This program adds two numbers num1 = 1.5 …