The document outlines a series of programming assignments that cover various topics including prime number functions, list manipulations, matrix operations, sorting algorithms, file handling, exception management, and object-oriented programming concepts. Each assignment specifies tasks such as defining functions, writing programs, and implementing classes with specific methods. The assignments are structured to enhance programming skills through practical applications.
The document outlines a series of programming assignments that cover various topics including prime number functions, list manipulations, matrix operations, sorting algorithms, file handling, exception management, and object-oriented programming concepts. Each assignment specifies tasks such as defining functions, writing programs, and implementing classes with specific methods. The assignments are structured to enhance programming skills through practical applications.
NO NO SIGNATURE Define a function prime(n) that returns True if n is prime and 0 otherwise. Use this function to do the following: Print the prime factors of a number. Print the first 10 terms of prime Fibonacci series. Test whether a number is a prime product or not. 1-2 1 (Note: A positive integer m is a prime product if it can be written as p×q, where p and q are both primes.) You may use separate functions for each of the above three problems Write a function contracting(l) that takes as input a list of 2 integersl and returns True if the absolute difference 3 between each adjacent pair of elements strictly decreases; and False otherwise Write a program that shuffles two lists l1 and l2 in a third list sl in the following manner: sl should consist of the first element in l1, then the first element in l2, then the second 4 element inl1, then the second element in l2, and so on. If 3 the two lists are not of equal length, the remaining elements of the longer list are appended at the end ofsl. In a list of integers l, the neighbours of l[i] are l[i-1] and l[i+1]. l[i] is a hill if it is strictly greater than its neighbours and a valley if it is strictly less than its neighbours. 5 4 Define a function counthv(l) that takes as input a list of integers las argument and returns a list [hc,vc] where hc is the number of hills in l and vc is the number of valleys in l Write a program to perform matrix addition, matrix subtraction and matrix multiplication by simulating matrix 6-8 using list of lists. You may use separate functions for each 5 operation Write a program to do Gaussian addition on a list of numbers. Print each partial sum and also the final sum. The program should be able to handle lists having both odd 9 lengths and even lengths. 6 (Eg: If the list is [11, 2, 30, 40, 5, 6], the program should output “11 + 6 =17”, “2 + 5=7”, and “30 + 40 = 70” in separate lines, and the result of the addition “94”.) Write a program that finds the Jaccard similarities between two sets. 7 10 8 Write a program that performs insertion sort over a list of 11 strings. 9 Write a program to input two lists, sort them and then 12 merge them into third list in a sorted manner. Define a dictionary to store names of footballers along with 13 10 the number of goals they have scored in world cups. Sort the dictionary is descending order of goals. Display the footballer, who has scored the highest number of goals. Write a program to accept two filenames as command line 11 arguments. Then copy the contents of one file into another adding line number to each line. Incorporate validation 14 checks wherever applicable. Write a program to input a list of integers, numlist[]. Then find the HCF of the numlist[2] and numlist[8]. Incorporate routines to handle any type of exceptions that may arise. 15-16 12 (Note: Common exceptions in this problem may be NameError, ZeroDivisionError, IndexError, ValueError etc) Define a class called MyPoint, which models a 2D point with x and y coordinates. Include the following: A constructor that initializes a 2D point. A method setXY() to set both x and y. 17-18 A method getXY() which returns the x and y in a list 13 A method to print a point using special member functions. A method to add two points. A method to compute the distance between this point and another point passed as argument. A method to test whether two points are coincident or not. Write a program to implement the above. Derive a class Point3D inherited from the class MyPoint in 14 problem 12. This class should model a 3D point with x, y 19-21 and z co-ordinates. Include all the functions in MyPoint class to perform corresponding operations in a 3D point 15 Incorporate the concept of public, private and protected data members in the above class. 22-24 Write a program to input two strings and print a new string 16 where the first string is reversed, and the second string is converted to upper case. 25 Example- input: “pets“, “party”, output: “step PARTY”. Write a program that initializes a list of words, and then join 17 all the words in the odd and even indices to form two 26 strings. 18 Write a program to simulate stack and queue using lists. 27-30