Assignmnet 6
Assignmnet 6
Kurnool (IIITDMK)
Department of Computer Science and Engineering
Python Programming Laboratory(S2-B.Tech CSE)
Assignment 6
1. Write a program to find the distance between two points, given by the coordinates (x1, y1) and
(x2, y2). By the Pythagorean theorem, the distance is:
3. Write a Python program to find index position and value of the maximum and minimum values in
a given list of numbers using lambda.
Original list:
[12, 33, 23, 10.11, 67, 89, 45, 66.7, 23, 12, 11, 10.25, 54]
Index position and value of the maximum value of the said list:
(5, 89)
Index position and value of the minimum value of the said list:
(3, 10.11)
4. Write a Python program to count the occurrences of the items in a given list using lambda.
Original list:
[3, 4, 5, 8, 0, 3, 8, 5, 0, 3, 1, 5, 2, 3, 4, 2]
Count the occurrences of the items in the said list:
{3: 4, 4: 2, 5: 3, 8: 2, 0: 2, 1: 1, 2: 2}
5. Write a Python function that prints out the first n rows of Pascal's triangle.
Note : Pascal's triangle is an arithmetic and geometric figure first imagined by Blaise Pascal.
Sample Pascal's triangle :
7. Write a program to print twin primes less than 1000. If two consecutive odd numbers are both
prime then they are known as twin primes
Output:
Twin Prime:
3 and 5
5 and 7
11 and 13
17 and 19
29 and 31
41 and 43
59 and 61
71 and 73
101 and 103
107 and 109
137 and 139
149 and 151
179 and 181
191 and 193
197 and 199
227 and 229
239 and 241
269 and 271
281 and 283
311 and 313
347 and 349
419 and 421
431 and 433
461 and 463
521 and 523
569 and 571
599 and 601
617 and 619
641 and 643
659 and 661
809 and 811
821 and 823
827 and 829
857 and 859
881 and 883
8. Write a program to implement the following formulae of permutations and combinations.
Number of permutations of n objects taken r at a time: p(n, r) = n! / (n-r)!.
Number of combinations of n objects taken r at a time is: c(n, r) = n! / (r!*(n-r)!) = p(n,r) / r!
Sample Input:
15 4
Output
Permutation: 32760
Combination: 1365
9. Write a function cubesum() that accepts an integer and returns the sum of the cubes of individual
digits of that number. Use this function to make functions PrintArmstrong() and isArmstrong() to
print Armstrong numbers and to find whether is an Armstrong number.
Sample Input
371
1000
Output
True
Armstrong: [0, 1, 153, 370, 371, 407]
10. Write a function sumPdivisors() that finds the sum of proper divisors of a number. Proper
divisors of a number are those numbers by which the number is divisible, except the number itself.
For example proper divisors of 36 are 1, 2, 3, 4, 6, 9, 18
Output:
55