Sei sulla pagina 1di 14


1) Write the description and syntax for the following python keywords .

Keywords Description























2) Vishal was reading some paraphrases by his friends. Now, he is interested in

classifying all the paraphrases he knows. He thinks that all paraphrases which contain
the word “loves” are selected, paraphrases that do not contain it are “not selected”.
Write a Python program for the given Paraphrases .
He loves to eat Butterscotch ice cream.
He always loves to play cricket.
I’m a Data Analyst.
Data Science is a blend of various tools.
All the Statisticians loves to do Data Science.
K L University is a deemed to be University.
3) Mathematicians are fond of numbers. All the mathematicians gave a task to the
Python programmers to write a program whether the given three digited numbers are
Armstrong numbers or not. If the given number is an Armstrong number then print “Yes
it is” otherwise print “Its not an Armstrong number”.
Input numbers : 369


1) There are two friends Sravan and Rohan walking beside a tree with N nodes (numbered 1 to
N), each of them with speed 1 edge per second. The walk of the sravan is described by a
sequence of nodes u1,u2,…,uK and Sravan appears in node u1 at time 0 and walks to node u2
using the shortest path; then, immediately after reaching u2, walks to node u3 using the shortest
path, and so on, until reaching uK, when this person disappears. The walk of the Rohan is
described by another sequence v1,v2,…,vL in the same manner. Count how many times these
two people meet — in other words, how many times they reach the same node (including the
first and last nodes of their walks) at the same time.

1.In this task, we would like for you to appreciate the usefulness of the groupby() function of itertools

. To read more about this function, Check this out .

You are given a string S . Suppose a character 'c' occurs consecutively X times in the string.

Replace these consecutive occurrences of the character 'c' with (X , c) in the string.

For a better understanding of the problem, check the explanation.

Input Format

A single line of input consisting of the string S.

Output Format

A single line of output consisting of the modified string.


All the characters of S denote integers between 0 and 9

1 <= |S| <=10 4 .

Sample Input

Sample Output

(1, 1) (3, 2) (1, 3) (2, 1)


First, the character 1 occurs only once. It is replaced by (1,1) . Then the character 2 occurs three

times, and it is replaced by (3,2) and so on.

Also, note the single space within each compression and between the compressions.

2. The itertools module standardizes a core set of fast, memory efficient tools that are useful by

themselves or in combination. Together, they form an iterator algebra making it possible to construct

specialized tools succinctly and efficiently in pure Python.

To read more about the functions in this module, check out their documentation here.

You are given a list of N lowercase English letters. For a given integer K, you can select any K

indices (assume 1-based indexing) with a uniform probability from the list.

Find the probability that at least one of the K indices selected will contain the letter: 'a'.

Input Format

The input consists of three lines. The first line contains the integer N, denoting the length of the list.

The next line consists of N space-separated lowercase English letters, denoting the elements of the

The third and the last line of input contains the integer K , denoting the number of indices to be


Output Format

Output a single line consisting of the probability that at least one of the K indices selected contains

the letter:'a'.

Note: The answer must be correct up to 3 decimal places.


1<= N <=10

1 <= K <=N

All the letters in the list are lowercase English letters.

Sample Input

Sample Output


All possible unordered tuples of length 2 comprising of indices from 1 to 4 to are:

(1,2) , (1,3) , (1,4) , (2,3) , (2,4) , (3,4)

Out of these 6 combinations, 5 of them contain either index 1 or index 2 which are the indices that

contain the letter 'a'.

Hence, the answer is 5/6 .

3. You are given a function f(X) = X2. You are also given lists. The ith list consists of Ni elements.
You must pick one element from each list so that the value from the equation below is maximized:

S= (f(X1) + f(X2) + ……..+ f(Xk)) % M

X i denotes the element picked from the list . Find the maximized value S max obtained.

% denotes the modulo operator.

Note that you need to take exactly one element from each list, not necessarily the largest element.

You add the squares of the chosen elements and perform the modulo operation. The maximum

value that you can obtain, will be the answer to the problem.

Input Format

The first line contains 2 space separated integers K and M.

The next K lines each contains an integer Ni, denoting the number of elements in the i th list, followed

by Ni space separated integers denoting the elements in the list.


1 <= K <=7

1<= M <= 1000

1<= Ni <=7

1 <= Magnitude of elements in list <=109

Output Format

Output a single integer denoting the value Smax.

Sample Input

3 1000
5 5 7 8 9 10
Sample Output

Picking 5 from the 1st list,9 from the 2nd list and from the 3rd list gives the maximum S value equal to

(52 + 92 + 10 2) % 1000 = 206.


1) There is a car race which consists of N laps. Zack entered the competition with his car
with X litres of fuel. There are gas stations available in between to refuel the vehicle but
here comes an interesting saga that states when you stop at the ‘i’th gas station, p(i)
amount of fuel is drained for sure. Find the number of laps Zack crosses before his car
gets out of fuel.

1)Write a program to compute the sum of the diagonal element of a given

2) Write a NumPy program to compute the eigenvalues and eigenvectors of
a 3x3 matrix.

3) Solve the given system of linear equation using python


4)Two brothers leave from the same location, one in a car and the other on a
bicycle, to meet up at their grandmother’s house for dinner. If one brother
averages 30 km per hour in the car and the other averages 12 km per hour on the
bicycle, then it takes the brother on the bicycle 1 hour less than 3 times as long
as the other in the car.
Frame the linear equations and solve them using python.
Find out and Display,how long does it take each of them to make the trip?


1) Vinay takes out his Snake and Ladder game, stares at the board and wonders: "If I can always
roll the die to whatever number I want, what would be the least number of rolls to reach the
Rules: The game is played with a cubic die of 6 faces numbered 1 to 6.
* Starting from square 1, land on square 100 with the exact roll of the die. If
moving the number rolled would place the player beyond square 100, no move is
* If a player lands at the base of a ladder, the player must climb the ladder.
Ladders go up only.

*If a player lands at the mouth of a snake, the player must go down the snake and
come out through the tail. Snakes go down only.