Tag: Python programs
Python Program to Check if a Number is Odd or Even
In this Python program, let’s learn how you can check a given number if it is odd or even. How to Check if a Number is Odd or Even in Python? A number is a even number if it is perfectly divisible by 2 i.e if the remainder is 0. In Python, you can use the modulus operator (%) to find the remainder. If the…
Python Program to add two integers
Problem Write a program in Python to add two integers and display the result on the screen. Python Program to add two integers Output Enter first number: 1 Enter second number: 2 1 + 2 = 3.0
Python Program to Find the Largest Value Among Three Numbers
This Python program shows you how you can use the conditional if else statement in Python to find the largest among three numbers and display the result. How to Find the Largest Value among three numbers in Python? Output The largest number among 3 Numbers is 65. In the above python program, the input numbers are stored in the variables number1,number2,number3 respectively. The conditional if…
Python Program to Find the Factorial of a Number
In this Python program, you will learn how to find the factorial of a number and display it using the print statement. Before we start coding, its important to understand what is a factorial. The factorial of a number is the product io all the number from 1 until that number. To give you an example , lets say you want to find the factorial…
Python Program to Calculate the Area of Triangle
This Python program shows how you can calculate the area of a triangle in python and display it using the python’s print method. How to Calculate the area if a triangle in Python? Assume that you have three variables side1,side2 and side3 which refers to the three sides of a triangle. The area of the triangle is calculated with the formula as shown below. area…
Python Program to Check If a Given Year is Leap Year
This Python program will demonstrate how you can check to see if a given year is a leap year or not. A leap year is a year that is exactly divisible by 4 except for the years that end with 00. For the years that ends with 00 , it is considered to be a leap year if it is divisible by 400. How to…
Python Program to Add Two Numbers
This Python program demonstrates how you can add two numbers in python and display it using the print() function. Python Program to Add Two Numbers Python program to add two numbers Output The sum of 898.2 and 111.6 is 1009.8000000000001 In this program , the variables number1 and number2 contains the numeric values that needs to be added. These two variable values are added and…
Python Program to Check Prime Number
This Python program demonstrates how you can check if a given number is a prime number or not. A number is a prime number if the following confitions are satisfied It is a Positive Number It is Greater than 1. Has no other factors except 1 and the number itself. Some of the examples of a prime number are 2,3 etc. How to Check if…
Python Program to Print Prime Numbers in a Given Interval
This Python program explains how you can print prime numbers in a given interval in python using loops. A number is a prime number if the following conditions are satisfied It is a Positive Number It is Greater than 1. Has no other factors except 1 and the number itself. Some of the examples of a prime number are 2,3 etc. How to Print Prime…
Python Program to Display Hello world
This is a simple program written in Python language that displays Hello World. The programs demonstrates how the Python code looks like and is a beginner program. Python Program to Display Hello world Output This program uses the python’s built-in print function to display the string Hello, world in the screen. The strings in python are by default in either single quotes , double quotes…
Python Program to Swap Two Variables
In this Python program , you will learn how to swap two variables easily with 2 options. Swap two variable using a temporary variable in python. Swap two variable without using temporary variable in python. How to Swap two variables in Python without using Temporary Variable? Output a : 3b : 8 How to Swap Two variables without using Temporary variable in Python? There are…
Python Program to Find the Square Root of Number
This python program will demonstrate how you can find the square root of a number using exponent operator python. Basic Program to find Square Root for Positive Number in Python Output The square root of 4.000 is 2.000 In this python program , we use the exponent operator ** to find the square root of the given positive number.
Python Program to Generate Multiplication Table
In this Python program, you will learn how to use loops in python to generate and display multiplication table of a given number. How to Generate and Display Multiplication Table in Python? Output 8 x 1 = 88 x 2 = 168 x 3 = 248 x 4 = 328 x 5 = 408 x 6 = 488 x 7 = 568 x 8 =…
Python Program to Check if a Number is Positive, Negative or Zero
In this python program, you’l learn how to check for a number of it is a positive , negative or zero. We will be using the conditional statements in python to solve this problem. How to find if a number is positive, negative or zero? Output The number that you entered is a Positive number A number is considered to be positive if it is…
Python Program to display "Hello, World!"
Problem Write a program in Python to display “Hello, World!” on the screen. Python Program to display “Hello, World!” in Console Window. This is a simple Python program that displays “Hello, World!” on the console window. Output Hello, World! The above Python program uses the print() function to display the Hello,World! string to the screen. Note that the strings are enclosed inside the single quotes…
Python – How do list all files of a directory?
In Python ,you can list all files of a directory using the os.listdir(). How do list all files of a directory in Python? You can use the os.listdir() in pythpn which will list all the files that is in the directory includes files and directories. Incase you want just the files , you can filter it using the path function.
Python Program to Print Fibonacci Series
In this Python program, you will learn how to generate and print Fibonacci series using loops and conditional statements. What is a Fibonacci Sequence ? A Fibonacci sequence is an sequence of integers where the value of the sequence is determined by adding the preceding two values. The first two values in the sequence is 0 and 1. Then comes Next one with (N-1) +…