0% found this document useful (0 votes)
33 views

Python Hello World

The document contains 6 Python code snippets that demonstrate: 1) Printing "Hello World", 2) Calculating the sum of two numbers, 3) Finding the square root of a number, 4) Calculating the area of a triangle, 5) Solving a quadratic equation, and 6) Swapping the values of two variables.

Uploaded by

Amal Jesudas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Python Hello World

The document contains 6 Python code snippets that demonstrate: 1) Printing "Hello World", 2) Calculating the sum of two numbers, 3) Finding the square root of a number, 4) Calculating the area of a triangle, 5) Solving a quadratic equation, and 6) Swapping the values of two variables.

Uploaded by

Amal Jesudas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

Python Hello World

print('Hello, world!')

2. Sum of two numbers

num1 = 1.5

num2 = 6.3

sum = num1 + num2

print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))

3. Square root

num = 8

num_sqrt = num ** 0.5

print('The square root of %0.3f is %0.3f'%(num ,num_sqrt))

4. Area of a triangle

a=5

b=6

c=7

s = (a + b + c) / 2

area = (s*(s-a)*(s-b)*(s-c)) ** 0.5

print('The area of the triangle is %0.2f' %area)

5. Quadratic equation

import cmath

a=1

b=5

c=6

d = (b**2) - (4*a*c)

sol1 = (-b-cmath.sqrt(d))/(2*a)

sol2 = (-b+cmath.sqrt(d))/(2*a)

print('The solution are {0} and {1}'.format(sol1,sol2))


6. Swap two variables

x=5

y = 10

temp = x

x=y

y = temp

print('The value of x after swapping: {}'.format(x))

print('The value of y after swapping: {}'.format(y))

You might also like