Beruflich Dokumente
Kultur Dokumente
1) Write the description and syntax for the following python keywords .
Keywords Description
and
as
break
continue
del
def
except
import
in
is
lambda
not
if
else
or
false
true
elif
for
while
return
yield
raise
try
assert
Skill2
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.
Skill3
1.In this task, we would like for you to appreciate the usefulness of the groupby() function of itertools
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.
Input Format
Output Format
Constraints
Sample Input
1222311
Sample Output
First, the character 1 occurs only once. It is replaced by (1,1) . Then the character 2 occurs three
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
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
list.
The third and the last line of input contains the integer K , denoting the number of indices to be
selected.
Output Format
Output a single line consisting of the probability that at least one of the K indices selected contains
the letter:'a'.
Constraints
1<= N <=10
1 <= K <=N
Sample Input
4
aacd
2
Sample Output
0.8333
Explanation
Out of these 6 combinations, 5 of them contain either index 1 or index 2 which are the indices that
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:
X i denotes the element picked from the list . Find the maximized value S max obtained.
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 next K lines each contains an integer Ni, denoting the number of elements in the i th list, followed
Constraints
1 <= K <=7
1<= Ni <=7
Output Format
Sample Input
3 1000
254
3789
5 5 7 8 9 10
Sample Output
206
Explanation
Picking 5 from the 1st list,9 from the 2nd list and from the 3rd list gives the maximum S value equal to
Skill4
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.
Skill5
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?
Skill6
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
destination?"
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
made.
* 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.