Basic programs in python

Jagadeshwaran_D
3 min readMay 19, 2021

Hi everyone, This is my new initiative. Keep support me

For more programs https://github.com/Jagadeshwaran-D/Python_Basic_programs

photo by Shahadat Rahman on Unsplash

What is Python?

Python is a general-purpose, dynamic, high-level, and interpreted programming language. It supports Object Oriented programming approach to develop applications. It is simple and easy to learn and provides lots of high-level data structures. Python is a programming language that lets you work more quickly and integrate your systems more effectively.

It is used for:

  • web development (server-side),
  • software development,
  • mathematics,
  • system scripting.

Python First Program

We all Know the first program of every programming language is Print “Hello World”

code

print(“Hello World”)

Example 1: Add Two Numbers

In this program, we asked the user to enter two numbers and this program displays the sum of two numbers entered by the user. We use the built-in function input()to take the input. Since returns a string, we convert the string into a number using the int() function. Then, the numbers are added and display the result.

Example 2: Squareroot of Given number

In this program, we use the inbuilt function sqrt() to find out the square root of the given number

Example 3: Conversion of Decimal value into Binary, octal, hexadecimal value

In this program ,we use the inbuilt function bin() for convert into a binary value,oct() for convert into a octal value, hex() for convert into a hexadecimal value.

Example 4: Solve Quadratic Equation

We have imported the cmath module to perform complex square root. First, we calculate the discriminant and then find the two solutions of the quadratic equation.

Example 5: Generate a Random number

To generate random numbers in Python, randint()function is used. This function is defined in a random module.

Example 6: Convert Kilometers into miles

In this program, the user is asked to enter kilometers. This value is stored in the kilometers variable. Since 1 kilometer is equal to 0.621371 miles, we can get the equivalent miles by multiplying kilometers with this factor.

Example 7: Convert Celsius to Fahrenheit

In this program, we take a temperature in degree Celsius and convert it into degree Fahrenheit by this mathematical formula

fahrenheit=(celsius*1.8)+32

Example 8: Calculate Simple Interest

In this program, we get user input as principal amount, year, interest with the help of these we calculate simple interest.

For more programs https://github.com/Jagadeshwaran-D/Python_Basic_programs

--

--