Python Assignment 8
Python Assignment 8
NAME-raushan kumar
1. SE
COURCE-BCA `1st` YEAR
ROLL NO-23SCSE1040408
1. Python program to convert the temperature in degree centigrade to
Fahrenheit.
PROGRAM:-
OUTPUT:-
2. Python program to find the area of a triangle whose sides are given.
PROGRAM:-
s= (a+b+c)/2
area= (s*(s-a)*(s-b)*(s-c))**.5
print("The area of triangle",area)
OUTPUT:-
3. Python program to find the circumference and are a of a circle with a given
radius.
PROGRAM:-
area= 3.14*a*a
OUTPUT: -
multiply_values = 8*16*22*12*41
n=5
geometric_mean = (multiply_values)**(1/n)
print ('The Geometric Mean is: ' + str(geometric_mean))
OUTPUT: -
PROGRAM:-
total = 0
ele = 0
PROGRAM:-
def digitAverage(n):
digiSum, digiLen = 0, 0
while n:
digiLen += 1
digiSum += n % 10 n
= n//10
return (digiSum/digiLen)
print(digitAverage(642)) print(digitAverage(3504))
OUTPUT: -
4.0
3.0
print("{0} is Odd".format(num))
OUTPUT:-
Enter a number: 4
4 is Even
PROGRAM:-
def find_product(numbers):
product = 1 for
num in numbers:
product *= num
return product
find_product(numbers)
PROGRAM:-
if num % 5 == 0:
else:
OUTPUT:-
Enter an integer: 25
Is a multiple of 5
10. Python program to check whether the given integer is a multiple of both
5 and 7
PROGRAM:-
and 7")
OUTPUT: -
Enter an integer:35
Is a multiple of both 5 and 7
PROGRAM:-
sum = 0
for _ in range(10): n=
sum = sum + n
average = sum/10
OUTPUT:-
Enter a number: 10
Enter a number: 12
Enter a number: 98
PROGRAM:-
OUTPUT:-
13. Python program to find the sum of the digits of an integer using a
while loop
PROGRAM:-
def
getSum(n):
sum = 0 while
(n != 0):
return sum
n = 12345
print(getSum(n))
OUTPUT:-
15
14. Python program to display all the multiples of 3 within the range
10 to 50
PROGRAM:-
start = 10 end = 50 print("Multiples of 3 in the
OUTPUT:-
12
15
18
21
24
27
30
33
36
39
42
45
48
15. Python program to display all integers within the range 100-200
whose sum of digits is an even number
PROGRAM:-
def sum_of_digits(n):
OUTPUT:-
PROGRAM:-
def is_prime(num): if num <= 1:
num % 3 == 0:
return False
i=
or num % (i + 2) == 0:
return False
i += 6
return True
if is_prime(num):
OUTPUT:-
Enter an integer: 2
2 is a prime number
OUTPUT: -
Enter an integer: 1
PROGRAM:-
d=b**2-4*a*c d1=d**0.5
if(d<0):
r1=(-b+d1)/2*a r2=(-b-d1)/2*a
OUTPUT:-
Equation: ax^2 + bx + c
Enter a: 14
Enter b: 8
Enter c: 9
PROGRAM:-
def factorial(n):
if n == 0:
return 1 # 0! is defined as 1
else:
return n * factorial(n - 1) num =
if num < 0:
OUTPUT:-
Enter a non-negative integer: 3
The factorial of 3 is 6
PROGRAM:-
0: print(num)
OUTPUT:-
Odd numbers in the array:
9
20. Python program to implement linear search
PROGRAM:-
def linear_search(arr, target):
for i in range(len(arr)):
if arr[i] == target:
return i
OUTPUT:-
PROGRAM:-
def binary_search(arr, target):
if arr[mid] == target:
else:
# Input: Create a sorted array (list) of elements (you can modify this as needed) arr
binary_search(arr, target)
if result != -1:
OUTPUT:-
50 is found at index 4
23. Python program to find the largest number in a list without using
built-in functions PROGRAM:-
# Input: Create a list of numbers (you can modify this as needed) numbers
= numbers[0]
largest = number
OUTPUT:-
# Input: Get the number to insert and the position from the user
{numbers}") else:
35 inserted at position 3. Updated list: [10, 20, 30, 35, 40, 50]
PROGRAM:-
def is_palindrome(s):
if is_palindrome(input_string):
OUTPUT 1:-
'kayak' is a palindrome.
OUTPUT2:-
Enter a string: SWATI
return result
return result
for i in range(len(A)):
for j in range(len(B[0])):
for k in range(len(B)):
[4, 5, 6],
[7, 8, 9]]
[3, 2, 1]]
matrix_A: print(row)
matrix_B:
print(row)
result_addition:
print(row)
result_subtraction:
print(row)
result_multiplication:
print(row)
OUTPUT:-
Matrix A:
[1, 2, 3]
[4, 5, 6]
[7, 8, 9]
Matrix B:
[9, 8, 7]
[6, 5, 4]
[3, 2, 1]
Matrix Addition:
Matrix Subtraction:
[-2, 0, 2]
[4, 6, 8]
Matrix Multiplication:
def find_diagonal_elements(matrix):
for i in range(len(matrix)):
diagonal_elements.append(matrix[i][i])
return diagonal_elements
else:
return "The matrix is not square, so it doesn't have diagonal elements."
# Example matrix
[4, 5, 6],
[7, 8, 9]]
diagonal_elements = find_diagonal_elements(matrix)
OUTPUT:-
Diagonal elements of the matrix are: [1, 5, 9]
={
"name": "John",
"age": 30,
print(f"{key}: {value}")
OUTPUT:-
name: John
age: 30 city:
New York
= turtle.Screen()
window.title("Circle inside
Square")
= turtle.Turtle()
draw_square(side_length):
for _ in range(4):
pen.forward(side_length) pen.right(90)
draw_circle(radius):
pen.circle(radius)
# Set the initial position of the turtle
pen.pendown()
= 100 pen.color("blue")
draw_square(square_length)
pen.pendown()
pen.color("red") draw_circle(circle_radius)
window.exitonclick()
range(len(matrix1))]
for i in range(len(matrix1)):
for j in range(len(matrix2[0])):
for k in range(len(matrix2)):
result[i][j] += matrix1[i][k] * matrix2[k][j]
return result
= [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
[6, 5, 4],
[3, 2, 1]]
print(row)
OUTPUT:-
Result of matrix multiplication:
return True
else:
return False
# Get user input for the year year
is_leap_year(year):
year.")
OUTPUT:-
Enter a year: 2021
COMPLETE