Code

Python Program 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 Output The value of x after swapping: 10 The value of y after swapping: 5 In this program, we use the temp variable to hold the value of x temporarily. We then put…

Code

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 Output The area of the triangle is 14.70 In this program, area of the triangle is calculated when three sides are given using Heron’s formula. If…

Code

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 Output The square root of 8.000 is 2.828 In this program, we store the number in num and find the square root using the ** exponent operator. This program works for all positive real numbers. But…

Code

Python Program to Print Hello world!

A simple program that displays “Hello, World!”. It’s often used to illustrate the syntax of the language. Source Code Output Hello, world! In this program, we have used the built-in print() function to print the string Hello, world! on our screen. By the way, a string is a sequence of characters. In Python, strings are enclosed inside single quotes, double quotes,…