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

Python Final File

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)
24 views

Python Final File

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/ 12

Q1.

Compute sum, subtraction, multiplication, division and


exponent of given variables input by the user.

a = float(input("Enter first number: "))


b = float(input("Enter second number: "))
print("Sum:", a + b)
print("Subtraction:", a - b)
print("Multiplication:", a * b)
print("Division:", a / b)
print("Exponent:", a ** b)
Compute area of following shapes: circle, rectangle, triangle,
square, trapezoid and
parallelogram.

r=int(input("enter the radius of circle --> "))


print("area of circle is --> ",3.14*r*r)

l=int(input("\nenter the length of rectangle --> "))


b=int(input("enter the breadth of rectangle --> "))
print("area of rectangle is --> ",l*b)

s1=int(input("\nenter the first side of the triangle --> "))


s2=int(input("enter the second side of the triangle --> "))
s3=int(input("enter the third side of the triangle --> "))
d=(s1+s2+s3)/2
print("\narea of triangle is --> ",(d*(d-s1)*(d-s2)*(d-s3))**0.5)

sq=int(input("\nenter the side of square --> "))


print("area of square is --> ",sq*sq)

a=int(input("\nenter first side of the trapezium --> "))


b=int(input("enter second side of the trapezium --> "))
h=int(input("enter the height of the trapezium --> "))
print("area of trapezium is --> ",0.5*(a+b)*h)

l=int(input("\nenter the side of parallelogram --> "))


b=int(input("enter the base of parallelogram --> "))
print("area of parallelogram is --> ",l*b)
Compute volume of following 3D shapes: cube, cylinder, cone and
sphere.

import math
s = float(input("Enter side of cube: "))
r_cyl = float(input("Enter radius of cylinder: "))
h_cyl = float(input("Enter height of cylinder: "))
r_cone = float(input("Enter radius of cone: "))
h_cone = float(input("Enter height of cone: "))
r_sph = float(input("Enter radius of sphere: "))
print("Volume of Cube:", s ** 3)
print("Volume of Cylinder:", math.pi * r_cyl ** 2 * h_cyl)
print("Volume of Cone:", (1/3) * math.pi * r_cone ** 2 * h_cone)
print("Volume of Sphere:", (4/3) * math.pi * r_sph ** 3)
Compute and print roots of quadratic equation ax2+bx+c=0,
where the values of a, b,
and c are input by the user

import math
a = float(input("Enter coefficient a: "))
b = float(input("Enter coefficient b: "))
c = float(input("Enter coefficient c: "))
d = b ** 2 - 4 * a * c
if d >= 0:
r1 = (-b + math.sqrt(d)) / (2 * a)
r2 = (-b - math.sqrt(d)) / (2 * a)
else:
r1 = complex(-b / (2 * a), math.sqrt(-d) / (2 * a))
r2 = complex(-b / (2 * a), -math.sqrt(-d) / (2 * a))
print("Roots:", r1, r2)
Print numbers up to N which are not divisible by 3, 6, 9,, e.g., 1,
2, 4, 5, 7,…

N = int(input("Enter a number N: "))

for i in range(1, N + 1):


if i % 3 != 0 and i % 6 != 0 and i % 9 != 0:
print(i, end=', ')
Write a program to determine whether a triangle is isosceles or
not?

a = float(input("Enter length of side a: "))


b = float(input("Enter length of side b: "))
c = float(input("Enter length of side c: "))

if a == b or b == c or a == c:
print("The triangle is isosceles.")
else:
print("The triangle is not isosceles.")
Print multiplication table of a number input by the user.

num = int(input("Enter a number: "))

for i in range(1, 11):


print(num, 'x', i, '=', num * i)
Compute sum of natural numbers from one to n number

n = int(input("Enter a natural number n: "))


sum_n = sum(range(1, n + 1))
print("Sum of natural numbers from 1 to", n, "is:", sum_n)
Print Fibonacci series up to n numbers e.g. 0 1 1 2 3 5 8 13…..n

n = int(input("Enter the number of terms in Fibonacci series: "))


a, b = 0, 1

for i in range(n):
print(a, end=' ')
a, b = b, a + b
Compute factorial of a given number

n = int(input("Enter a number: "))


factorial = 1

for i in range(1, n + 1):


factorial *= i

print("Factorial of", n, "is:", factorial)


Count occurrence of a digit 5 in a given integer number input by
the user.

num = input("Enter an integer number: ")


count_five = num.count('5')
print("The digit 5 occurs", count_five, "times.")
Print Geometric and Harmonic means of a series input by the
user.

import math

numbers = list(map(float, input("Enter numbers separated by spaces: ").split()))

g_mean = math.prod(numbers) ** (1 / len(numbers))


h_mean = len(numbers) / sum(1 / num for num in numbers)

print("Geometric Mean:", g_mean)


print("Harmonic Mean:", h_mean)

You might also like