You are on page 1of 1

Python Lab Assignment – 5 (27/09/2022)

1. Assuming a1b2 –a2b1≠0, the solution of the linear equations a1x +b1y = c1 and a2x+b2y=c2 is given by
x = (b2c– b1c2)/ (a1b2 –a2b1), y = (a1c2 – a2c1)/ (a1b2 –a2b1). Write a program which reads a1, b1, c2, a2,
b2,c2 calculate x and y and prints the output.
2. Write a program to find roots of ax2 + bx + c =0 where a, b, c are real numbers and a≠0
3. Write a program to determine whether A, B, C can form the sides of a triangle. If yes, compute the
perimeter of the triangle, if no print the message ‘Not a triangle’ (Hint: A, B, C can form a triangle if
each side a less than the sum of the other Two sides ie if A<B+C, B<A+C and C<A+B.)
4. Write a program to reverse the digits of a five-digit number.
5. Write a program to calculate nCr.
6. A University gives distinctions if the average marks in an exam are 75% or above, first class, if the
average marks are 60% or above, second-class, if the marks are below 50% or above. A candidate
fails if these marks are below 50%. Write a program, which reads the marks in five subjects and
displays the result.
7. Write a program to check the points (x1, y1), (x2, y2) and (x3, y3) are collinear.
8. Suppose the health insurance premium is deduced from an employee’s salary according to the
following plan premium = 9.75% if TYPE = 1, p = 16.25% if TYPE = 2 and 24.50% if TYPE = 3.
Write a program deducing the premium from an employee’s salary assuming his PAY, TYPE and ID
as input.
9. Write a program to print out all Armstrong numbers between 1 and 500. If sum of cubes of each
digit of the number is equal to the number itself, then the number is called Armstrong number. (Ex:
153= (1*1*1) +(5*5*5) +(3*3*3))
10. Euclidian Algorithm to compute GCF: let a and b are two numbers if r is the remainder after dividing
a by b, then if r = 0 then d is the GCF otherwise replace a by b and b by r and repeat the process.
Write a program to implement this algorithm.
11. Write a program to compute the sum 1 + 1.2 + 1.2.3 + 1.2.3.4 + … 1.2.3… n.
12. A perfect number is a number that is equal to sum of all its divisor except itself. An abundant number
is one, which is less than the sum of its divisors. A deficient number is greater than sum of its divisors.
Write a program to generate a table of first N integers and classify each as perfect, abundant or
deficient.
13. Given a set of n points (x1, y1), (x2, y2) … (xn, yn). The straight line through these points which is the
n xi yi −  xi  yi 1
best approximation is y = mx + c where n = and c =   yi − m xi  . Write
n x − (  x )
2
2 n
i i

a program to fit this straight line.

You might also like