# Python solved programs with output and explanation

Python is a general-purpose, high-level, simple but effective object-oriented programming approach based, and an interpreted programming language. It’s very easy to learn (due to emphasized code readability) and powerful programming language.

This is the best way to learn Python programming by practicing the **Python programs**. This section contains **Python solved programs** on various topics such as basic programs, conditional & control statement-based programs, arrays programs, matrices programs, string programs, lists programs, dictionaries, file handling, data structure programs, etc.

## Python basic programs

- How to print spaces in Python?
- Python | Printing different messages by using different variations of print() method.
- Python program to print given text using a user-defined method
- Python | Printing different values (integer, float, string, Boolean).
- Python | Declare different types of variables, print their values, types and Ids.
- Python program to demonstrate variables scope
- Determine the type of an object in Python
- Create number variables (int, float and complex) and print their types and values in Python
- Create integer variable by assigning binary value in Python
- Create integer variable by assigning octal value in Python
- Create integer variable by assigning hexadecimal value in Python
- Python | Typecasting Input to Integer, Float.
- How to check multiple variables against a value in Python?
- Python | Program to define an integer value and print it.
- Python | Input two integers and find their addition.
- Python program to find sum of two numbers
- Python program to find addition of two numbers (4 different ways)
- Python Arithmetic Operators Example
- Python program to print ASCII value of a character
- Python program for simple interest
- Python program for compound interest
- Python program to check the given year is a leap year or not
- Simple pattern printing programs in Python
- Create a function to check EVEN or ODD in Python
- Create a function to return the absolute the given value in Python
- Python program to check whether a given number is a Fibonacci number or not
- Python program to find power of a number using exponential operator
- Python program to find the power of a number using loop
- Python program to find the power of a number using recursion
- Python program to extract and print digits in reverse order of a number
- Python program to reverse a given number (2 different ways)
- Python program to find floor division
- Python | Some of the examples of simple if else.
- Python | Input age and check eligibility for voting.
- Python | Find largest of three number using nested if else.
- Python | Calculate discount based on the sale amount.
- Python | Calculate discount based on the sale amount using Nested if else.
- Python | Example of Ternary Operator
- Python | Design a simple calculator using if elif (just like switch case)
- Python | Demonstrate an example of for loop
- Python | Demonstrate an example of for each loop
- Python | Examples of loops (based on their control)
- Python | Some of the Examples of loops
- Python | Demonstrate an Example of break statement
- Python | Demonstrate an Example of continue statement
- Python | Demonstrate an Example of pass statement
- Python | Program to print numbers from N to 1 (use range() with reverse order).
- Python | Print all numbers between 1 to 1000 which are divisible by 7 and must not be divisible by 5.
- Python | Calculate square of a given number (3 different ways).
- Python | Find factorial of a given number (2 different ways).
- Python | Find the factorial of a number using recursion
- Python | Write functions to find square and cube of a given number.
- Python | Declare any variable without assigning any value.
- Python | BMI (Body Mass Index) calculator.
- Python | Program to print Odd and Even numbers from the list of integers.
- Python | Program to print Palindrome numbers from the given list.
- Python | Compute the net amount of a bank account based on the transactions.
- Python | Count total number of bits in a number.
- Python | Generate random number using numpy library.
- Generate random integers between 0 and 9 in Python
- Python | Program to calculate n-th term of a Fibonacci Series
- Python program to check prime number
- Python program to calculate prime numbers (using different algorithms) upto n
- Python program for not None test
- Python program for pass statement
- Python program to define an empty function using pass statement
- Python program for Zip, Zap and Zoom game
- Python program to convert temperature from Celsius to Fahrenheit and vice-versa
- Python program to find the number of required bits to represent a number in O(1) complexity
- Python program to count number of trailing zeros in Factorial of number N
- Python program for swapping the value of two integers
- Python program for swapping the value of two integers without third variable
- Python program to find winner of the day
- Python program for Tower of Hanoi
- Python program to find standard deviation
- Python program to find the variance
- Python program Tower of Hanoi (modified)
- Python program to convert Centimeter to Inches
- Python program to convert meters into yards
- Python program to convert yards into meters
- Python program to capitalize the character without using a function
- Python program to lowercase the character without using a function
- Python program to find perfect number
- Python program to print perfect numbers from the given list of integers
- Python program to design a dice throw function
- Python program to design a biased dice throw function
- Python program to design a biased coin flip function
- Python program to design a coin flip function
- Python program to find greatest integer using floor() method
- Python program to find the maximum EVEN number
- Python program to find the maximum ODD number
- Python program to find the solution of a special sum series
- Python | Convert the binary number to decimal without using library function
- Python | Convert the decimal number to binary without using library function
- Create a stopwatch using Python
- Python program to find the maximum multiple from given N numbers
- Python program to find the least multiple from given N numbers
- Find the root of the quadratic equation in Python
- Python program to check the given Date is valid or not
- Python program to print the calendar of any year
- Find all Prime numbers less than or equal to N using the Sieve of Eratosthenes algorithm in Python
- Find the sum of all prime numbers in Python
- Print the all uppercase and lowercase alphabets in Python
- Find the N-th number which is both square and a cube of a number in Python
- Program to find the execution time of a program in Python
- Program to find the x-intercept and y-intercept of a line passing through the given point in Python
- Find the day of the week for a given date in the past or future in Python
- Python program to find the GCD of the array
- Python program to find the LCM of the array elements
- Find the number of integers from 1 to n which contains digits 0's in Python
- Check whether a number is a power of another number or not in Python
- Check whether the binary representation of a given number is a palindrome or not in Python
- Draw a pie chart that shows our daily activity in Python
- Find the sum of all numbers below 1000 which are multiples of 3 or 5 in Python
- Python | How can I force division to be floating point? Division keeps rounding down to 0?
- Python program to print the list of all keywords
- Python program to print the version information
- Python program to find sum of all digits of a number
- Print number with commas as thousands separators in Python
- Python program to print table of number entered by user
- Python program to calculate currency notes required to get the amount
- Python program to calculate discount based on selling price
- Python program to calculate gross pay (Hourly paid employee)
- Python program to get employee details and search for record by ID, surName or Designation
- Python program for Basic Shop Management System
- More ...

## Python array programs

- Python program to find the sum of all elements of an array
- Python program to find a series in an array consisting of characters
- Python program to find the occurrence of a particular number in an array
- Find the union and intersection of two arrays in Python
- Python program to create matrix in Python
- More ...

## Python string programs

- Python | Declare, assign and print the string (Different ways).
- Python | Access and print characters from the string.
- Python program to print a string, extract characters from the string.
- Python | Program to print words with their length of a string.
- Python | Print EVEN length words.
- More ...

## Python Class and Object programs

- Python example to define a class
- Python | Demonstrate an example of Class and Object
- Python | Simple program of a class (Input and print a number)
- Public variables in Python
- Python | Create Employee class with some attributes and methods
- More ...

## File handling programs

- Append content to a file in Python
- Read contents of the file using readline() method in Python
- Read contents of a file using readline() method and manipulating it in Python
- Copy odd lines of one file to another file in Python
- Setting file offsets in Python
- More ...

## Python Data Structures Programs

- Python program for Bubble Sort
- Python program for Insertion Sort
- Python program for Selection Sort
- Python program for Linear Search
- Breadth First Search for a Graph in Python
- More ...

## Python exception handling programs

- Python exception handling program (Handling divide by zero exception)
- Python exception handling program (Handling Type exception)
- Python program to illustrate importing exception from another file
- Python program to illustrate the import exception defined in another file and defining a new one
- More ...

## Python database (SQL/MySQL) programs

- Python program to create an SQL table
- Python program to display SQL table content
- Insertion of Records to Database in Python
- Fetch employee details from the database whose salary lies within a certain range in Python
- Delete a Record from the Database in Python
- More ...

## Python Threading Programs

- Python program to illustrate naming of threads
- Python Program to illustrate parameterized threads
- Python program to illustrate multithreading
- Python program to create and delete threads using sleep method
- Python program for multithreading with class
- More ...

## Python Date & Time Programs

- Python program to get current date
- Python program to get current time
- Python program to print today's year, month and day
- Python program to print current hour, minute, second and microsecond
- Python program to print all timezones using pytz module

## Python programs on int class

- Python program to find number of bits necessary to represent an integer in binary
- Python program to print number of bits to store an integer and also print number in Binary format
- Python program to print an array of bytes representing an integer
- Python program to print the binary value of the numbers from 1 to N

**Stack**

## Python List Programs

- Python | Program to declare and print a list.
- Python program to print list elements in different ways.
- Python | Program for Adding, removing elements in the list.
- Python | Program to print a list using ‘FOR and IN’ loop.
- Python | Program to add an element at specified index in a list.
- Python | Program to remove first occurrence of a given element in the list.
- Python | Remove all occurrences a given element from the list.
- Python | Program to remove all elements in a range from the List.
- Python | Program to sort the elements of given list in Ascending and Descending Order.
- Python | Program to find the differences of two lists.
- More Python List Programs ...

## Python Dictionary Programs

- Python program to create an empty dictionary
- Python program to create a dictionary using dict() function
- Python program to create a dictionary from a sequence
- Python program to create a dictionary with integer keys, and print the keys, values & key-value pairs
- Python program to create a dictionary with mixed keys, and print the keys, values & key-value pairs
- Python | Generate dictionary of numbers and their squares (i, i*i) from 1 to N
- Python program to search student record stored using Dictionary
- Python program for accessing elements from a dictionary
- Python program for adding elements to a dictionary
- How to compare two dictionaries in Python?
- More Python Dictionary Programs ....

## Python Regular Expression Programs

- Python Regex | program to Remove leading zeros from an IP address
- Python program to understand difference between match() and search() methods
- Python program to check the presence of substring in given string - Regex Example
- Python program to check whether a regular expression is present in string or not
- Python program to extract phone number from string using sub() method
- More...

## Python Lambda Function Programs

- Python program to illustrate the working of lambda functions on array
- Python program to apply lambda functions on array
- Python program to filter even values from list using lambda function
- Python program to find the sum of elements of a list using lambda function
- More Python Lambda Function Programs ...

## Python searching programs

## Python game programs

- Python program for rolling the dice (2-player dice game)
- Snakes and ladder (Single player) in Python

## Python miscellaneous programs

- Design Traditional and Magic Calculator in Python3
- Python | Create a line plot using matplotlib.pyplot
- Python | Create a bar chart using matplotlib.pyplot
- Python | Create a bar graph with using matplotlib.pyplot
- Python | Create a stacked bar using matplotlib.pyplot
- Python | Create a scatter plot using matplotlib.pyplot
- Python | Create pie-chat using matplotlib.pyplot
- Python | Create stack plot using matplotlib.pyplot
- Python program for plotting in same and different graph
- Histogram using Pylab in Python
- Python program for single dice simulation
- Python program for single biased dice simulation
- Python program for biased coin flipping simulation
- Python program for double biased dice simulation
- Python program for double dice (one biased one normal) simulation
- Python program to generate the QR code in Python
- Greedy algorithm for a knapsack problem with the example of Robbery in Python
- Corona Virus Live Updates for India (District Wise) – Using Python
- English dictionary application using Python
- Emotional and Sentiment Analysis with the help of Python
- Control Mouse in Python
- Edge Detection of Image using OpenCV (CV2) in Python
- Cropping an Image using OpenCV in Python
- Converting an OpenCV Image to Black and White in Python

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions