You are on page 1of 4

NAME: CHAKKILAM TARUN SIDDARDHA

REGISTRATION NUMBER: 21MIC7027

ASSIGNMENT – 2
SWE1004-INTRODUCTION TO PROGRAMMING IN PYTHON

1) Python Program to Find the Square Root


CODE:
mport math
x = float(input("Enter a number: "))
root_x = math.sqrt(x)
print("Square root of entered number = ",root_x)

OUTPUT:

2) Python Program to Calculate the Area and Perimeter of Triangle and


Circle.

AREA AND PERIMETER OF TRIANGLE:


CODE:
#Area And Perimeter Of Triangle
import math

side_1 = float(input("Enter the value of side-1: "))


side_2 = float(input("Enter the value of side-2: "))
side_3 = float(input("Enter the value of side-3: "))
perimeter = side_1+side_2+side_3
s = perimeter/2
value_1 = s-side_1
value_2 = s-side_2
value_3 = s-side_3
value = s*value_1*value_2*value_3
area = math.sqrt(value)
if area == 0:
    print("The triangle can't be formed with given side values")
else:
    print("Perimeter of triangle is ",perimeter)
    print("Area of triangle is ", area)

OUTPUT:

AREA AND PERIMETER OF CIRCLE:


CODE:
import math
radius = float(input("Please Enter The Value Of RADIUS: "))
perimeter = 2*math.pi*radius
print("Perimeter of circle with radius",radius,"is",perimeter)
area = math.pi*radius*radius
print("Area of circle with radius",radius,"is",area)

OUTPUT:

3) Python Program to Solve Quadratic Equation


CODE:
import cmath
a = float(input("Enter the coefficient of x: "))
b = float(input("Enter the coefficient of y: "))
c = float(input("Enter the constant: "))
equation = str(a)+'x^2'+'+'+str(b)+'y^2'+'+'+str(c)
print(equation)
value_1 = b**2
value_2 = 4*a*c
value_3 = 2*a
discriminant = value_1-value_2
root_of_discriminant = cmath.sqrt(discriminant)
numenator_1 = -b + root_of_discriminant
numenator_2 = -b - root_of_discriminant
denomenator = value_3
root_1 = numenator_1/denomenator
root_2 = numenator_2/denomenator
print("The roots of given equation ","is ", root_1, "and", root_2)

OUTPUT:

4)Python Program to Swap Two Variables 


CODE:
x = int(input("Enter the value of x (The value should be of int type
only):"))
y= int(input("Enter the value of y (The value should be of int type only):
"))
s = x
x  = y
y = s
print("The swapped variables are:")
print("x = ",x)
print("y = ",y)

OUTPUT:

5)Python Program to Convert Kilometres to Miles 


CODE:
kilometres = float(input("Enter Number Of Kilometres: "))
miles = kilometres*0.621371
if kilometres == 1.0:
    print(kilometres," Kilometre = ",miles,' miles')
else:
    print(kilometres," Kilometres = ",miles,' miles')

OUTPUT:

6) Python Program to Convert Celsius To Fahrenheit:


CODE:
Celsius = float(input("Enter the value of Temperature in Celsius: "))
temp_in_fh = (Celsius*9/5)+32
print(Celsius,u"\N{DEGREE SIGN}","C in Fahrenheit = ",temp_in_fh,"F")

OUTPUT:

You might also like