0% found this document useful (0 votes)
23 views5 pages

Assignmnet 6

The document provides instructions for submitting assignments and includes 10 programming problems related to Python. The problems cover a range of topics including finding the distance between points, filtering lists with lambda, analyzing lists, generating Pascal's triangle, checking for perfect numbers, finding twin primes, permutations and combinations, Armstrong numbers, and summing proper divisors.

Uploaded by

123ad0006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views5 pages

Assignmnet 6

The document provides instructions for submitting assignments and includes 10 programming problems related to Python. The problems cover a range of topics including finding the distance between points, filtering lists with lambda, analyzing lists, generating Pascal's triangle, checking for perfect numbers, finding twin primes, permutations and combinations, Armstrong numbers, and summing proper divisors.

Uploaded by

123ad0006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Indian Institute of Information Technology, Design & Manufacturing,

Kurnool (IIITDMK)
Department of Computer Science and Engineering
Python Programming Laboratory(S2-B.Tech CSE)

Assignment 6

Last date for submitting : 16/04/2024 22:00 Hrs

Naming Conventions for Submission


Submit a single ZIP (.zip) file (do not submit in any other archived formats like .rar or .tar.gz).
The name of this file must be ASSG<NUMBER>_<ROLLNO>_<FIRSTNAME>.zip. (eg:
ASSG1_118cs0006_LAXMAN.zip). DO NOT add any other files (like temporary files,
inputfiles, etc.) except your source code, into the zip archive. The source codes must be named
as ASSG<NUMBER>_<ROLLNO>_<FIRSTNAME>_<PROGRAM-NO>.<extension>. (For
example: ASSG1_118cs0006_LAXMAN_1.py). If there are multiple parts for a particular
question, then name the source files for each part separately as in
ASSG1_118cs0006_LAXMAN_1b.py.
If you do not conform to the above naming conventions, your submission might not be
recognized by some automated tools, and hence will lead to a score of 0 for the submission. So,
make sure that you follow the naming conventions.

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:

Hint: Use Fruitful Functions


2. Write a Python program to filter a list of integers using Lambda.
Original list of integers:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Even numbers from the said list:
[2, 4, 6, 8, 10]
Odd numbers from the said list:
[1, 3, 5, 7, 9]

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 :

6. Write a Python function to check whether a number is "Perfect" or not.


According to Wikipedia : In number theory, a perfect number is a positive integer that is equal to
the sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number
itself (also known as its aliquot sum). Equivalently, a perfect number is a number that is half the
sum of all of its positive divisors (including itself).
Example : The first perfect number is 6, because 1, 2, and 3 are its proper positive divisors, and 1 +
2 + 3 = 6. Equivalently, the number 6 is equal to half the sum of all its positive divisors: ( 1 + 2 + 3
+ 6 ) / 2 = 6. The next perfect number is 28 = 1 + 2 + 4 + 7 + 14. This is followed by the perfect
numbers 496 and 8128.

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

You might also like