Вы находитесь на странице: 1из 6

PTYHON PROGRAM TO FIND AREA OF A TRIANGLE

# Python Program to find the area of triangle

# Three sides of the triangle a, b and c are provided by the


user

a = float(input('Enter first side: '))

b = float(input('Enter second side: '))

c = float(input('Enter third side: '))

# calculate the semi-perimeter

s = (a + b + c) / 2

# calculate the area

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

print('The area of the triangle is', area)

OUTPUT:

Enter first side:5

Enter second side:6

Enter third side:7

The area of the triangle is 14.70


PYTHON PROGRAM TO CALCULATE SIMPLE INTEREST

P = float(input("Enter the principal amount : "))

N = float(input("Enter the number of years : "))

R = float(input("Enter the rate of interest : "))

SI = (P * N * R)/100

print('Simple interest:', SI)

OUTPUT:

Enter the principal amount : 50000

Enter the number of years : 5

Enter the rate of interest : 6

Simple interest: 15000


PYTHON PROGRAM TO FIND AREA OF A CIRCLE

# Python Program to find Area Of Circle using Radius

PI = 3.14

radius = float(input(' Please Enter the radius of a circle: '))

area = PI * radius * radius

circumference = 2 * PI * radius

print(" Area Of a Circle =", area)

print(" Circumference Of a Circle =", circumference)

OUTPUT:

Please Enter the radius of a circle: 4

Area Of a Circle = 50.24

Circumference Of a Circle = 25.12


PYTHON PROGRAM TO SWAP TWO VARIABLES

# Python program to swap two variables

num1 = input('Enter First Number: ')

num2 = input('Enter Second Number: ')

print("Value of num1 before swapping: ", num1)

print("Value of num2 before swapping: ", num2)

# swapping two numbers using temporary variable

temp = num1

num1 = num2

num2 = temp

print("Value of num1 after swapping: ", num1)

print("Value of num2 after swapping: ", num2)

OUTPUT:

Enter First Number: 101

Enter Second Number: 99

Value of num1 before swapping: 101

Value of num2 before swapping: 99

Value of num1 after swapping: 99

Value of num2 after swapping: 101


PYTHON PROGRAM TO CEHCK WHETHER YEAR IS LEAP
YEAR OR NOT

# User enters the year

year = int(input("Enter Year: "))

# Leap Year Check

if year % 4 == 0 and year % 100 != 0:

print(year, "is a Leap Year")

elif year % 100 == 0:

print(year, "is not a Leap Year")

elif year % 400 ==0:

print(year, "is a Leap Year")

else:

print(year, "is not a Leap Year")

OUTPUT:

Enter Year: 2000

2000 is not a Leap Year


NAME: GAUTAM SINGH
ROLL NO.: 11
CLASS: XI(B)
SUBJECT: COMPUTER SCIENCE

Вам также может понравиться