Assignment 0:
Ques 1) What is the circumference of a circle inscribed inside a rectangle with a length of 8 meters and breadth of 4 meters ? (1 point )
- 12.57
- 25.132
- 6.28
- 50.27
Accepted Answers : 12.57
Ques 2) What is the sum of the first 27 odd numbers? (1 point)
- 8109
- 729
- 27
- 108
Accepted Answers : 729
Ques 3) What is the Least Common Multiple of 12 and 8? (1 point)
- 2
- 12
- 8
- 24
Accepted Answers : 24
Quest 4) If the length of the square is thrice its original length, its perimeter will be 120 meters. What is the original length of the square? (1 point)
- 30
- 10
- 40
- 20
Accepted Answers : 10
Ques 5) In a class, there are 80 students who have taken science which is 40% of the total strength. 20% of students have taken maths and the remaining students have taken english. How many students have taken english? (1 point)
- 80
- 400
- 200
- 40
Accepted Answers : 80
Ques 6) Find the next number of the sequence 1, 5, 13, 25, _______ (1 point)
- 29
- 41
- 33
- 37
Accepted Answers : 41
Ques 7) If the perimeter of the square is 100, what is the area of the square? (1 point)
- 10000
- 2500
- 625
- 1000
Accepted Answers : 625
Ques 8) If the circumference of the circle is 31.4, what is the area of the circle? (1 point)
- 78.5
- 314
- 15.6
- 15.6
Accepted Answers : 78.5
Ques 9) What is the golden value ratio? (1 point)
- 1.618
- 1.168
- 1.861
- None of the above.
Accepted Answers : 1.618
Ques 10) Choose the odd one out. 1, 2, 3, 5 (1 point)
- 1
- 5
- 3
- None of the above
Accepted Answers : 1
Assignment 1:
Ques 1) What is the value of var after double clicking on the below block of code in scratch? (1 point)
- 7.5
- 5
- 3
- 50
Accepted Answers : 5
Ques 2) Choose the odd one out. wait, repeat, forever, move (1 point)
- wait
- repeat
- forever
- move
Accepted Answers : move
Ques 3) How far will the sprite be from the initial position after executing this block of code? (1 point)
- 141.42 steps
- 100 steps
- 10 steps
- 200 steps
Accepted Answers : 141.42 steps
Ques 4) What is the name of the command used to reshow the hidden sprite? (1 point)
- reappear
- show
- undo hide
- visible
Accepted Answers : show
Ques 5) The command used to make the sprite rotate by a certain degree is ? (1 point)
- turn
- rotate
- revolve
- bend
Accepted Answers : turn
Ques 6) The command used to delay the sprite by a few seconds is ________ (1 point)
- wait
- hold
- stop
- None of the above
Accepted Answers : wait
Ques 7) What will the sprite recite when the below block of code is executed? (1 point)
- All even numbers from 1 to 100
- All even numbers from 1 to 200
- All odd numbers from 1 to 100
- All odd numbers from 1 to 200
Accepted Answers : All odd numbers from 1 to 200
Ques 8) Which of the following does not belong to the motion command ? (1 point)
- move
- turn
- glide
- None of the above
Accepted Answers : None of the above
Ques 9) What is the command to increase the size of the sprite? (1 point)
- increase size
- change size by
- expand
- zoom in
Accepted Answers : change size by
Ques 10) When will the sprite stop moving when this block of code is executed ?
- Never
- It will stop after a while
- It will stop after 100 rounds
- None of the above
Accepted Answers : Never
Assignment 2:
Ques 1) What will be the output for the following program if the user gives an input value of 3 to it? (1 point)
c=input("Enter a number")
print(c*5)
- 15
- 33333
- Error message
- 555
Accepted Answers : 33333
Ques 2) Which of these statements in python will throw anerror when executed? (1 point)
- print( “Hello” )
- print( ‘Hello’ )
- print( “ ‘Hello’ “ )
- print( “ “Hello” ” )
Accepted Answers : print( “ “Hello” ” )
Ques 3) What will be the output of the following code when executed? (1 point)
for i in range(3,30,3)
print(i)
- It will print numbers from 3 to 30
- It will print multiples of 3 till 30
- It will print multiples of 3 till 27
- It will print 3 thirty times
Accepted Answers : It will print multiples of 3 till 27
Ques 4) What will the output of the following code be when executed? (1 point)
c=30
a=4
print(c/a)
print(c//a)
- 7.5
7 - 7.5
7.5 - 7
7 - 7.5
2
Accepted Answers : 7.5
7
Ques 5) What value will c store in it after the execution of the below code? (1 point)
- Value of b multiplied by 3
- Cube of b
- Value of b multiplied with 3 twice
- It will throw an error
Accepted Answers : Cube of b
Ques 6) Python was named after the television show Monty Python's Flying Circus. (1 point)
- False
- True
Accepted Answers : True
Ques 7) What will the output of the following program be? (1 point)
c=input()
print(type(c))
- < class 'str' >
- < class 'int' >
- < class 'number' >
- < class 'variable ' >
Accepted Answers : < class 'str' >
Ques 8) What will the output of the following program be? (1 point)
- It will show an error
- Hello! Welcome to Joy of Computing using Python course
- 47
- a+b
Accepted Answers : Hello! Welcome to Joy of Computing using Python course
Ques 9) The python files will be saved with a .python extension. (1 point)
- False
- True
Accepted Answers : False
Ques 10) What is the output for the following program? (1 point)
a=3
b=4
c=a>b
print(c)
- True
- False
- It will display an error message
- Boolean
Accepted Answers : False
Assignment 3:
Ques 1) List items are ordered, changeable, and do not allow duplicate values. State true or false. (1 point)
- True
- False
Accepted Answers : False
Ques 2) What will the output of the following program be? (1 point)
- All numbers from 1 to 10
- All even numbers from 1 to 10
- All odd numbers from 1 to 10
- It will give an error
Accepted Answers : All odd numbers from 1 to 10
Ques 3) What will the output of the following program be?
- [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
- [1, 2, 3, 4, 5, 6, 7, 999, 8, 9, 10]
- It will give an error
- [999, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Accepted Answers:
[1, 2, 3, 4, 5, 6, 7, 999, 8, 9, 10]
Ques 4) Which command will insert the new element to the list at the end? Consider the name of the list to be Shopping and the new element to be inserted is “oil”.
- Shopping.append(“oil”)
- Shopping.insert(len(Shopping),”oil”)
- Both option a and b
- Shopping.add(“oil”)
Accepted Answers : Both option a and b
Ques 5) Which method is to find out how many times a particular list element occurs? (1 point)
- count
- repeat
- unique
- sum
Accepted Answers : count
Ques 6) Which of these methods is used to find the mean of the below defined list? a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]. (1 point)
- statistics.median(a)
- stats.median(a)
- median(a)
- average(a)
Accepted Answers : statistics.median(a)
Ques 7) Which of these following statements is true regarding trimmed mean? (1 point)
- It removes a small percentage of the largest and smallest values before calculating the mean
- Trimmed mean is also known as truncated mean
- Both a and b are true
- Trimmed mean removes a small percentage of largest value before calculating the mean
Accepted Answers : Both a and b are true
Ques 8) What is the output of the following program? (1 point)
- H+e+l+l+o
- +Hello+
- +H+e+l+l+o
- +Hello
Accepted Answers : H+e+l+l+o
Ques 9) Which of these methods is used to jumble a given word and give an output separated by a “ , “ symbol? (Consider the string to be stored in variable a). (1 point)
- “ , ”.join(random.sample(a, len(a)))
- random.sample(a, len(a)).join( “ , “ )
- random.sample(a, len(a))
- It is not possible to jumble a word
Accepted Answers : “ , ”.join(random.sample(a, len(a)))
Ques 10) Which method can be used to remove an element at a particular index from the list? (1 point)
- pop( )
- delete( )
- discard( )
- The element cannot be removed
Accepted Answers : pop( )
Assignment 4:
Ques 1) What is the magic constant or magic sum of a magic square of size 11? (1 point)
- 671
- 121
- It is not possible to find
- Magic squares only exists for even size
Accepted Answers : 671
Ques 2) In magic square, the first number will be stored at position (n/2, n-1). Let this position be (i, j). The second number will be stored at position (i+1, j-1). State whether the following statement is true or false. (1 point)
- True
- False
Accepted Answers : False
Ques 3) The below given matrix is a magic square. State whether the following statement is true or false. (1 point)
- False
- True
Accepted Answers : True
Ques 4) What will the output of the following program be? (1 point)
- In the year 1900, february has 28 days
- In the year 1900, february has 29 days
- In the year 1900, february has 0 days
- It will throw an error
Accepted Answers : In the year 1900, february has 28 days
Ques 5) Consider today's date to be 06-06-2021 and the day after tomorrow is tuesday.. What will be the output of the following program? (1 point)
- 22
0 - 0
22 - Monday
29 - 29
Tuesday
Accepted Answers : 22
0
Ques 6) What will the following program do? (1 point)
- Print the sum of digits of a given number
- Print the number by dividing it by 10
- Print the reverse of the number
- None of the above
Accepted Answers : Print the sum of digits of a given number
Ques 7) Which program will choose an element from the below list and display it in jumbled order? (1 point)
Accepted Answers :
Ques 8) There are a total of 100 cards of 25 different colors. How many minimum numbers of draws are required to guarantee that at least two drawn cards have the same color? (1 point)
- 100
- 26
- 25
- 50
Accepted Answers : 26
Ques 9) What does the following code snippet in python compute? (1 point)
- Factorial of numbers from 0 to 15
- Fibonacci series
- None
- Sequence of numbers from 0 to 15
Accepted Answers : Fibonacci series
Ques 10) Dobble game has a deck of 55 cards, each printed with eight different symbols. Any two cards always share one matching symbol only. State whether the above statement is true or false. (1 point)
- True
- False
Accepted Answers : True
Assignment 5:
Ques 1) What will the output of the following program be? (1 point)
- They are equal
- They are not equal
- It will throw an error
Accepted Answers : They are not equal
Ques 2) What will the output of the following program be? (1 point)
- name Joy of computing
Length 12 Weeks
Professor_name Dr Sudarshan Iyengar
Language Python - {'name': 'Joy of computing', 'Length': Sudarshan Iyengar', 'Language': 'Python'}
- It will throw an error
- dictB will be empty
Accepted Answers :
name Joy of computing
Length 12 Weeks
Professor_name Dr Sudarshan Iyengar
Language Python
Ques 3) A file with the .wav or .wave file extension is a Waveform Audio File Format. True or False? (1 point)
- False
- True
Accepted Answers : True
Ques 4) In the Monty Hall problem, under the standard assumptions, contestants who switch have a ___ chance of winning the car, while contestants who stick to their initial choice have only ___chance. (1 point)
- 1/2, 1/2
- 2/3, 1/3
- 1/3, 2/3
- 1/3, 1/3
Accepted Answers : 2/3, 1/3
Ques 5) In the game ‘Rock, Paper and Scissor’ , if player1 enters 123478 and player2 enters 347653 with the secrets bits as 3 and 5 respectively, then who wins the game? (Assume that player1_list=[“rock”, “paper”, “scissor”] and player2_list=[“paper” ,”scissor”, “rock”]) (1 point)
- Player1 wins the game
- Player2 wins the game
- It will be a draw
- Insufficient data
Accepted Answers : It will be a draw
Ques 6) Which is the fastest sorting algorithm? (1 point)
- Bubble Sort
- Bucket Sort
- Quick Sort
- Insertion Sort
Accepted Answers : Quick Sort
Ques 7) Which of these following statements are true with respect to the program below? (1 point)
- The value of sum will always be between 1 and 11
- The value of sum will be from 2 to 12
- The value of sum will be within 12
- The maximum value of sum cannot exceed 6
Accepted Answers : The value of sum will be from 2 to 12
Ques 8) What is the average time complexity of binary search if the numbers are arranged in descending order and the search is unsuccessful? (1 point)
- log2 (n+1)
- log2 (n)
- log2 (n^2)
- None of the following
Accepted Answers : log2 (n)
Ques 9) What Is the output of the following program? (1 point)
- 100
- 0
- 108
- 109
Accepted Answers : 100
Ques 10) Will the following program give an error? (1 point)
- Yes
- No
Accepted Answers : No
Assignment 6:
Ques 1) If PYTHON is SVWERK, what is COMPUTING? (1 point)
- FLPMXQLKJ
- FRPSXWLQJ
- Insufficient data
- ZLJMSQFKD
Accepted Answers : FLPMXQLKJ
Ques 2) What operation will the following program do? (1 point)
- Shift the letter by 6 to the right and then print the capital of that letter.
- Shift the letter by 6 to the left and then print the capital of that letter.
- Shift the letter by 6 to the right and then print the small letter.
- Shift the letter by 6 to the left and then print the small letter.
Accepted Answers : Shift the letter by 6 to the right and then print the capital of that letter.
Ques 3) What is the output of the following program? (1 point)
- False
- True
Accepted Answers : True
Ques 4) What will be the output of the following program? (1 point)
- ll,adwlolt o fcmuigcus
- hlo n lcm ojyo optn orl
- hello, and welcome to jy of computing course
- It will show an error
Accepted Answers : hlo n lcm ojyo optn orl
Ques 5) The array object in NumPy is called ndarray and NumPy is faster than Lists. State whether the above statement is true or false. (1 point)
- True
- False
Accepted Answers : True
Ques 6) What is the output of the following program? ( Assuming that k and n are any 2 positive numbers) (1 point)
- It will find the value of k raised to the power of k
- It will find the value of n raised to the power of k
- It will find the value of k raised to the power of n
- It will find the value of n raised to the power of n
Accepted Answers : It will find the value of k raised to the power of n
Ques 7) The output of the following program is as follows. (1 point)
[[ 1 4 13]
[ 2 2 9]
[ 3 3 6]]
What should be written in the empty blank in the following program to get the
above desired output?
- numpy.transpose(arr)
- arr.transpose( )
- Either a or b options can be used
- arr.reverse( )
Accepted Answers : Either a or b options can be used
Ques 8) Which of the following programs will calculate the factorial of a given number? (1 point)
- None of the following
Accepted Answers : None of the following
Ques 9) In tic tac toe game, if player 1 starts the game by marking ‘X’ in the center of the matrix, then he has more chances of winning. State whether the above given statement is true or false. (1 point)
- True
- False
Accepted Answers : True
Ques 10) Recursive programs are faster than the iterative programs. State whether the following statement is true or false. (1 point)
- True
- False
Accepted Answers : False
Assignment 7:
Ques 1) What will the following program do? (1 point)
- Rename the snakesandladders.png file as snakeimage.png
- Creates a new file called snakeimage.png
- Creates a new file called snakeimage.png with the same content as in the snakesandladders.png
- Invalid operation
Accepted Answers : Creates a new file called snakeimage.png with the same content as in the snakesandladders.png
Ques 2) Which of the following statements is wrong regarding csv? (1 point)
- CSV stands for Comma Separated Values
- It's a simple file format used to store tabular data, such as spreadsheet or database
- The use of the commas a field separator is the source of the name for this file format
- None of the above
Accepted Answers : None of the above
Ques 3) If a player has a score of 87 and rolls the dice in the snake and ladder game. If he gets a 5, what will be the player's position next considering the dictionary associated with the game? (1 point)
dict={
92:79,
95:51,
87:18,
62:22,
57:40,
52:29,
17:13,
80:100,
90:91,
75:86,
58:77,
28:84,
8:30,
3:21
}
- 79
- 97
- 92
- The player cannot be in position number 87
Accepted Answers : The player cannot be in position number 87
Ques 4) What will be the output of the following program? (1 point)
- 12 13 14 9 8 7 6 11 16 17 18 19 20 15 10 5 4 3 2 1
- 1 2 3 4 5 10 15 20 19 18 17 16 11 6 7 8 9 14 13 12
- 1 6 11 16 17 18 19 20 15 10 5 4 3 2 7 12 13 14 9 8
- 13 12 7 8 9 14 19 18 17 16 11 6 1 2 3 4 5 10 15 20
Accepted Answers : 12 13 14 9 8 7 6 11 16 17 18 19 20 15 10 5 4 3 2 1
Ques 5) The default drawing state of the turtle is pendown. State whether the above statement is true or fault. (1 point)
- True
- False
Accepted Answers : True
Ques 6) What is the output of the following program? (1 point)
- Octagon
- Pentagon
- Nonagon
- Hexagon
Accepted Answers : Octagon
Ques 7) While using the turtle speed method, the speed value 1 is faster than speed value 0. State whether the above statement is true or false. (1 point)
- True
- False
Accepted Answers : False
Ques 8) Which of these methods is used to make the turtle rotate 45 degrees in the anticlockwise direction. (1 point)
- tr.turn(-45)
- tr.right(-45)
- tr.left(45)
- Both b and c
Accepted Answers : Both b and c
Ques 9) Which of these packages allow us to plot data on google maps? (1 point)
- gmplot
- plot
- googleplot
- matplotlib.gmplot
Accepted Answers : gmplot
Ques 10) Which of these following methods will change the color of the lines that will be drawn by the turtle? (1 point)
- pencolor( )
- color( )
- Both a and b
- None of the above
Accepted Answers : Both a and b
Assignment 8:
Ques 1) Tuples are similar to lists in terms of indexing, nested objects and repetition but it is immutable unlike lists. State whether the above statement is true or false. (1 point)
- True
- False
Accepted Answers : True
Ques 2) Which of these following operations are not valid with respect to tuples? (1 point)
( Consider tuple names to be T1 and T2 with 5 elements in each of it)
- print( T1 + T2 )
- print( T1 * 3 )
- print( T1 [ -4 : -1 ] )
- del T1 [ 1 ]
Accepted Answers : del T1[1]
Ques 3) What is the output of the following program? (1 point)
- 1 2 3
- Error
- a b c
- t t t
Accepted Answers : 1 2 3
Ques 4) What will be the output of the following program? (1 point)
- It generates a random number and prints it
- It generates a random number and doesn't do anything
- It will generate a random number and prints it
- It will generate a random number and prints it only if its a multiple of 3
Accepted Answers : It will generate a random number and prints it only if its a multiple of 3
Ques 5) Which of these statements are false with respect to clahe? (1 point)
- CLAHE is a variant of Adaptive histogram equalization ( AHE ) which takes care of over-amplification of contrast.
- CLAHE operates on small regions in the image, called tiles, rather than the entire image.
- The neighbouring tiles are then combined using bilinear interpolation by including the artificial boundaries.
- It is used to improve the contrast of images.
Accepted Answers : The neighbouring tiles are then combined using bilinear interpolation by including the artificial boundaries.
Ques 6) What is the output of the following program? (1 point)
- Linear graph with positive slope
- Linear graph with negative slope
- Non linear graph with positive slope
- Non linear graph with negative slope
Accepted Answers : Linear graph with negative slope
Ques 7) What should be filled in the blank in the given program to obtain the below desired output? (1 point)
- pandas.DataFrame(data)
- tiger.DataFrames(data)
- tiger.Series(data)
- pandas.Series(data)
Accepted Answers : tiger.DataFrames(data)
Ques 8) VADER uses a combination of A sentiment lexicon is a list of lexical features which are generally labeled according to their semantic orientation as either positive or negative. State whether the following statement is true or false. (1 point)
- True
- False
Accepted Answers : True
Ques 9) What will the output of the following program be? (1 point)
- Prints the reverse of string a
- Prints the string only if its an anagram
- Prints the string only if its a palindrome
- Error message
Accepted Answers : Prints the string only if its a palindrome
Ques 10) If the compound score of a statement is 1.5. What can we infer from the compound statement? (1 point)
- It is an extremely positive statement
- It is and extremely negative statement
- It is a neutral statement
- Compound score cannot be 1.5
Accepted Answers : Compound score cannot be 1.5
Week 8: Programming Assignment 1 - Palindrome
Given a string as input, determine if it is a palindrome or not. (Ignore the spaces, case and any punctuation or special characters present in the string).
Note: A palindromes is a string which has characters in the same order when read forward or backwards.
Input Format
First line of the input contains a string
Output Format
Print 'Yes' if the given string is a palindrome, 'No' otherwise.
Example:
Input:
Malayalam
Output:
Yes
Input:
Python
Output:
No
Solution :
n=input()
n=''.join(s for s in n if s.isalpha()==True)
n=n.lower()
if(n==n[::-1]):
print("Yes",end="")
else:
print("No",end="")
Week 8: Programming Assignment 2 - Anagrams
Given two strings as input, determine if they are anagrams or not. (Ignore the spaces, case and any punctuation or special characters).
Note: Anagrams are the strings which are made up of the same set of letters. For example : Mary and Army are anagrams.
Input Format
First line of the input contains the first string
Second line of the input contains the second string
Output Format
Print 'Yes' if the given strings are anagrams, 'No' otherwise.
Example:
Input:
Tom Marvolo Riddle
I am Lord Voldemort!!!
Output:
Yes
Input:
Royal Challengers Bangalore
Rajasthan Royals
Output:
No
Solution:
s1=input()
s2=input()
s1=''.join(w for w in s1 if w.isalpha()==True)
s2=''.join(w for w in s2 if w.isalpha()==True)
s1=s1.lower()
s2=s2.lower()
if sorted(s1)==sorted(s2):
print("Yes",end="")
else:
print("No",end="")
Week 8: Programming Assignment 3 - Pangram
Given an English sentence, check whether it is a pangram or not. A pangram is a sentence containing all 26 letters in the English alphabet
Input Format:
A single line of the input contains a string
Output Format:
Print Yes or No
Example:
Input:
The quick brown fox jumps over a lazy dog
Output:
Yes
Input:
The world will be taken over by AI
Output:
No
Solution :
import string
def pangram(s):
alpha_s=string.ascii_lowercase
for w in alpha_s:
if(w not in s):
return False
return True
s=input()
s=s.lower()
if pangram(s)==True:
print("Yes",end="")
else:
print("No",end="")
Assignment 9:
Ques 1) Which of these features of the texts are not analyzed by the NLP for attributing authorship? (1 point)
- Jaccard similarity
- Stop words
- Word Length
- None of the above
Accepted Answers : None of the above
Ques 2) NetworkX can be used to solve large-scale problems that require faster approaches. State whether the above statement is true or false. (1 point)
- True
- False
Accepted Answers : False
Ques 3) What is the output of the following program? (1 point)
import networksx as nx
g=nx.Graph()
g.add_edge('a','b',weight=.1)
g.add_edge('b','c',weight=1.5)
g.add_edge('a','c',weight=1.0)
g.add_edge('c','d',weight=2.2)
print (nx.shortest_path(g,'b','d'))
- ['b', 'c', 'd']
- ['b', 'a', 'c', 'd']
- It will give an error
- ['d', 'a', 'c', 'b']
Accepted Answers : ['b', 'c', 'd']
Ques 4) Consider the following statements.
- subgraph(G, nbunch) - induce subgraph of G on nodes in nbunch
- union(G1,G2) - graph union
- disjoint_union(G1,G2) - graph union assuming all nodes are same
- cartesian_product(G1,G2) - return Cartesian product graph
Which of the statements are correct with respect to the above operations? (1 point)
- Only statements 1 and 2 are true
- Only statements 1 and 3 are correct
- All the above statements are correct
- Statements 1, 2 and 4 are correct
Accepted Answers : Statements 1, 2 and 4 are correct
Ques 5) Which of these following statements are true? (1 point)
- Six degrees of separation is the idea that all people on average are six, or fewer, social connections away from each other
- Six degrees of separation was originally developed by Frigyes Karinthy
- It is also called six handshakes rule
- All of the above
Accepted Answers : All of the above
Ques 6) What does nltk stand for? (1 point)
- Natural Language toolkit
- Neutral Language toolkit
- Natural Linguistic toolkit
- Neutral Linguistic toolkit
Accepted Answers : Natural Language toolkit
Ques 7) The Barabasi-Albert model is a model that generates _________ networks. (1 point)
- Scale-free networks
- Scale networks
Accepted Answers : Scale-free networks
Ques 8) The complete graph with n graph vertices has how many undirected edges? (1 point)
- n( n-1 )/2
- n-1
- ( n-1 )/2
- n
Accepted Answers : n( n-1 )/2
Ques 9) What will the following statement print? (1 point)
print(im.getpixel(coordinate))- Prints the coordinate of a particular pixel
- Prints the pixel RGB value specified by coordinate variable that contains both x and y value
- Error message
Accepted Answers : Prints the pixel RGB value specified by coordinate variable that contains both x and y value
Ques 10) What is the output of the following program? (1 point)
var="hello PYTHON"
print(var.casefold())
- Hello python
- HELLO PYTHON
- HELLO python
- hello python
Accepted Answers : hello python
Week 9: Programming Assignment 1 - Snakes and Ladders I
Given a configuration of a Snakes and Ladders board in the form of a mapping, determine the number of snakes and ladders.
Input Format
First line of the input contains the board configuration in the form of mapping of snakes and ladders.
Output Format
Print two space separated integers indicating the number of snakes and ladders respectively.
Example:
Input:
6:14, 11:28, 17:74, 22:7, 38:59, 49:12, 57:76, 61:54, 81:98, 88:4
Output:
4 6
Explanation:
In the given configuration, 6:14 indicates a ladder and 22:7 indicates a snake. There are 4 snakes and 6 ladders.
Solution :
snake_ladder = input().split()
snake = 0
ladder = 0
for i in range(len(snake_ladder)-1):
s = snake_ladder[i].split(':')
if(int(s[0]) > int(s[1][:-1])):
snake += 1
else:
ladder += 1
s=snake_ladder[-1].split(':')
if(int(s[0]) > int(s[1])):
snake += 1
else:
ladder += 1
print(snake,ladder,end="")
Week 9: Programming Assignment 2 - Snakes and Ladders II
Given the configuration of a Snakes and Ladders board and a series of numbers obtained when the die is rolled, determine if the sequence of the die rolls leads to a win.
Input Format
First line of the input contains the board configuration in the form of mapping of snakes and ladders
Second line of the input contains comma separated integers indicating the values obtained on rolling a die.
Output Format
Print Yes if the sequence of roll die leads to a winning combination, No otherwise.
Example:
Input:
6:14, 11:28, 17:74, 22:7, 38:59, 49:12, 57:76, 61:54, 81:98, 88:4
6, 3, 4, 3, 5
Output:
Yes
Explanation:
As per the given configuration, the above set of moves indicate that the winning number 100 is reached. Hence this is a winning combination. (It is a winning combination if the set of die rolls lead to a number equal to 100 or exceeds 100).
Solution :
snake_ladder = input().split(', ')
rolling_die = list(map(int,input().split(', ')))
board = {}
for s in snake_ladder:
s = s.split(':')
board[int(s[0])] = int(s[1])
board = dict(board)
score = 0
for die in rolling_die:
score += die
if (score in board.keys()):
score = board[score]
if score >= 100:
print("Yes",end="")
else:
print("No",end="")
Assignment 10:
Ques 1) Classify the following types of compressed image files as lossy or lossless compression type. (1 point)
(1) PNG
(2) JPEG
- (1) Lossless
(2) Lossey - (1) Lossey
(2) Lossless - (1) Lossless
(2) Lossless - (1) Lossey
(2) Lossey
Accepted Answers : (1) Lossless
(2) Lossey
Ques 2) Compression can be used to reduce or change file size and which of these following attributes? (1 point)
- File type
- Resolution
- Bit depth
- All of the above
Accepted Answers : All of the above
Ques 3) NumPy is a python library written partially in python and most parts that require fast computation are written in C or C++. State whether the following statement is true or false. (1 point)
- True
- False
Accepted Answers : True
Ques 4) What is the output of the following program ? (1 point)
import numpy as np
arr=np.array([[1,2,3,4,5,6],[6,5,4,3,2,1])
print(arr[1,-5])
- 5
- 2
- 2
- Error message
Accepted Answers : 5
Ques 5) What is the output of the following program? (1 point)
a = ['a','e','i','o','u','A','E','I','O','U',' ']
b = 'Hello have a good day'
for i in b:
if i not in a:
b = b[:b.index(i)] + b[b,index(i)+1:]
print(b)
- eo ae a oo a
- oe ae a oo a
- ae ae a oo a
- None of the above
Accepted Answers : eo ae a oo a
Ques 6) What is the output of the following program? (1 point)
def ring(str):
result = ""
for i in range(len(str)):
if i%2==0:
result = result + str[i]
return result
print(ring("Welcome to Joy of Computing Course"))
- Wloet o fCmuigCus
- ecm t Jyo CmuigCus
- Welcome to Joy of Computing Course
- None of the above
Accepted Answers : Wloet o fCmuigCus
Ques 7) What will the following function in the program do? (1 point)
def ring(text):
for line in text.split("\n"):
return " ".join(line.split()[::-1])
- Reverse all the strings in the sentence
- Reverse the sentence
- Reverse the first word of the sentence.
- None of the above
Accepted Answers : None of the above
Ques 8) Which of these methods can be used to transpose a matrix X? (1 point)
- X.Transpose( )
- X.T
- X.t( )
- X.transpose
Accepted Answers : X.T
Ques 9) What will the following program print? (1 point)
import numpy as np
arr = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
newarr = arr.reshape(4, 3)
print(newarr)
- We cannot reshape the array.
- [[ 1 2 3]
[ 4 5 6]
[ 7 8 9]
[10 11 12]] - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
Accepted Answers : [[ 1 2 3]
[ 4 5 6]
[ 7 8 9]
[10 11 12]]
Ques 10) What is the output of the following program? (1 point)
import numpy as np
a = np.array([1, 2, 3, 5, 8])
b = np.array([0, 3, 4, 2, 1])
c = a + b
c = c*a
print(c[2])
- 7
- 12
- 10
- 21
Accepted Answers : 21
Week 10 : Programming Assignment 1 - String Decomposition
Given a large string and a set of small strings, determine if it is possible to exactly decompose the given large string into the set of small strings. (Assume that all the strings are given in lowercase)
Input Format
The first line of the input contains a large string
The second line of the input contains space separated small strings
Output Format
Display Yes or No (no newline after the output)
Example:
Input:
abdefgbadklm
dab bad elmf kg
Output:
Yes
Input:
abdgefmnorst
frost badge lm
Output:
No
Explanation:
In the first case it is possible to construct the set of small strings by using exactly all the characters given in the original string. In the second case it is not possible.
large_string = input()
small_strings = input()
small_strings = small_strings.replace(" ","")
large_string = ''.join(sorted(large_string))
small_strings = ''.join(sorted(small_strings))
if large_string == small_strings:
print("Yes",end="")
else:
print("No",end="")
Week 10 : Programming Assignment 2 - Encryption
The alphabets are enumerated as A = 0, B = 1, C = 2, … , Z = 25. Consider an encryption scheme where a character with value C i in the plaintext is replaced by another character with value C j using the formula C j = (C i + 5) % 26. After replacement, the resulting string is shuffled (permuted) at random to obtain the cipher text. Given a plain text and a possible cipher text, your task is to determine whether the cipher text can be formed from the plain text using the above mentioned scheme. (Assume that all the strings are in uppercase)
Input Format
The first line of the input contains a string indicating the plain text.
The second line of the input a string indicating a possible cipher text
Output Format
Display Yes or No (no newline after the output)
Example:
Input:
PYTHON
TDMSUY
Output:
Yes
Input:
JOCPNPTEL
JQYVSUTHO
Output:
No
plainText = input()
cipherText = list(input())
for i in range(len(cipherText)):
asc=ord(cipherText[i])-ord('A')-5
if asc < 0:
asc = 26+asc
cipherText[i] = chr(asc+ord('A'))
plainText = sorted(plainText)
cipherText = sorted(cipherText)
if plainText == cipherText:
print("Yes",end="")
else:
print("No",end="")
Assignment 11:
Ques 1) The Python library used for browser automation is (1 point)
- numpy
- browser
- selenium
- pyautogui
Accepted Answers : selenium
Ques 2) Which method is used to obtain the element with a matching link text value? (1 point)
- find_element_by_link_text
- find_element_by_name
- find_element_by_tag_name
- find_element_by_id
Accepted Answers : find_element_by_link_text
Ques 3) What does the method find_element_by_class_name do ? (1 point)
- The first element with the given tag name will be returned.
- The first element with the matching class attribute name will be returned.
- The first element with the matching name attribute value will be returned.
- The first element with the matching CSS selector will be returned.
Accepted Answers : The first element with the matching class attribute name will be returned.
Ques 4) Which Python module allows us to work with date and time ? (1 point)
- dt
- dtime
- timedate
- datetime
Accepted Answers : datetime
Ques 5) Which method enables us to see the current date and time ? (1 point)
- today( )
- current( )
- now( )
- curdate( )
Accepted Answers : now( )
Ques 6) Which Python library allows us to perform time zone calculations ? (1 point)
- timezone( )
- tz( )
- pytz( )
- pytimezone( )
Accepted Answers : pytz( )
Ques 7) What would be the output of : print(calendar.weekday(2021,10,9)) (1 point)
- 4
- 5
- 3
- 6
Accepted Answers : 5
Ques 8) Which of the following conditional statements correctly return True for any leap year and False for any non-leap year ? (1 point)
- if ( ( year%100 == 0 or year%400 == 0 ) or (year%4 == 0 or year%100 != 0) )
- if ( ( year%100 == 0 and year%400 == 0) or (year%4 == 0 and year%100 != 0) )
- if ( ( year%100 == 0 and year%4 ==0 ) or year%400 == 0)
- if ( ( year%100 == 0 or year%4 == 0 ) and year%400 == 0)
Accepted Answers : if ( ( year%100 == 0 and year%400 == 0) or (year%4 == 0 and year%100 != 0) )
Ques 9) Which of the following statements can be used to print the calendar of October 2021? (1 point)
- calendar.month(2021, 10)
- calendar.month(10, 2021)
- calendar.month(Oct)
- calendar.month(Oct, 2021)
Accepted Answers : calendar.month(2021, 10)
Ques 10) What would be the output of the statement : print(datetime.datetime(2021, 9, 16)) ? (1 point)
- 2021-09-16 12:00:00
- 2021-09-15 23:59:59
- 2021-09-16 01:01:01
- 2021-09-16 00:00:00
Accepted Answers : 2021-09-16 00:00:00
Assignment 11: Programming Assignment 1 - Sorting of Words
Write a program to read a comma-separated set of words as input and print the words in a comma-separated sequence after sorting them alphabetically.
Input Format
The first line of input contains words separated by a comma.
Output Format
Print the sorted words separated by comma.
Example:
Input:
programming,hello,big,world
Output:
big,hello,programming,world
words = input().split(",")
words = sorted(words)
for i in range(len(words)):
if i< len(words)-1:
print(words[i],end=",")
print(words[-1],end="")
Assignment 11: Programming Assignment 2 - Punctuations
Given a string, remove all the punctuations in it and print the remaining characters.
Input Format
The first line of the input contains a string with punctuations.
Output Format
Display the string after removing the punctuations
Example:
Input:
“Wow!!! It’s a beautiful morning”
Output:
Wow Its a beautiful morning
puncutations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
words = input()
for i in words:
if i not in puncutations:
print(i,end="")
Assignment 11: Programming Assignment 3 - Solve the riddle
You are given a set of riddles. Each riddle will be in the form of a long string of jumbled alphabets (all the alphabets will be lowercase). As an answer to the riddle, you have to tell the length of the longest possible palindrome that can be formed from the given alphabet sequence. Note that the alphabets can be arranged in any sequence to form the palindrome.
Input Format
The first line contains an integer t indicating the number of test cases
Next t test cases follow
The single line of each test case contains a string of lowercase alphabets
1 ≤ t ≤ 100
1 ≤ Input String Length ≤ 1000
Output Format
For each test case, output the length of the largest possible palindrome that can be formed using the given string.
Example:
Input:
2
banana
abccdebbaa
Output:
5
7
Explanation:
If riddle is abccdebbaa,
The maximum length of the palindrome that can be formed is 7
(One such possible palindrome is cabbbac)
t = int(input())
while(t):
word = input()
poli = set(word)
polindrome=0
rest=0
for i in poli:
polindrome += word.count(i)-(word.count(i)%2)
rest += word.count(i)%2
if len(word)-polindrome>0:
polindrome += 1
print(polindrome)
Assignment 12:
Ques 1) In the point distribution method of page rank algorithm, at each iteration, each node shares its pagerank value by (1 point)
- Randomly choosing one of its outgoing links and sharing all its pagerank value to the node connected to that link.
- Dividing its pagerank value equally to all the outgoing links.
- Dividing its pagerank value randomly to all the outgoing links.
- Dividing its pagerank value to all the outgoing links with the value given being proportional to their outdegree.
Accepted Answers : Dividing its pagerank value equally to all the outgoing links.
Ques 2) In the random walk method, what is the next step when a sink node is encountered in the underlying graph? (1 point)
- random node is chosen out of all the given nodes.
- The node with the maximum number of incoming links is chosen.
- The node with the maximum number of outgoing links is chosen.
- The process stops at this stage.
Accepted Answers : random node is chosen out of all the given nodes.
Ques 3) According to the Google Page rank algorithm, the rank of a page depends on: A. Number of pages it is referring to. (1 point)
- Number of pages it is referring to.
- Number of pages referring to it.
- Rank of pages it is referring to.
- Rank of pages referring to it.
Accepted Answers : Number of pages referring to it.
Ques 4) Comment on the purpose of the following command. (1 point)
sorted(p.items(),key=operator.itemgetter(1))
- Sort the items of dictionary, p by key
- Sort the items of dictionary, p by values
- Sort the elements of list, p by values
- Sort the items of Tuple, p by values
Accepted Answers : Sort the items of dictionary, p by values
Ques 5) Which of the following is not true about Collatz Conjecture? (1 point)
- If the previous term is even, the next term is one half the previous term.
- If the previous term is odd, the next term is 3 times the previous term.
- If the previous term is odd, the next term is 3 times the previous term plus 1.
- No matter what value of n, the sequence will always reach 1.
Accepted Answers : If the previous term is odd, the next term is 3 times the previous term.
Ques 6) The sequence based on 3n+1 problem will always reach (1 point)
- True
- False
Accepted Answers : True
Ques 7) What is the sequence obtained according to the 3m+1 algorithm for m=9? (1 point)
- 28,14,7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1
- 28,14,7,22,11,34,52,26,13,40,20,10,5,16,8,4,2,1
- 28,14,7,22,11,17,52,26,13,40,20,10,5,16,8,4,2,1
- 28,14,7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1
Accepted Answers : 28,14,7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1
Ques 8) Consider the following statements: (1 point)
a) Random Walk method requires a lesser number of iterations to calculate accurate PageRank as compared to Points Distribution method.
b) Points Distribution method requires lesser number of iterations to calculate accurate PageRank as compare to Random Walk method
- Statement a is correct
- Statement b is correct
- Statement b is correct
Accepted Answers : Statement b is correct
Ques 9) In the web graph, nodes are the web pages. What are the edges? (1 point)
- Network Connections
- Links to other web pages
- URLs
- None of the above
Accepted Answers : Links to other web pages
Ques 10) How many iterations does the number, 75 take to converge in Collatz Conjecture? (1 point)
- 14
- 15
- 13
- 12
Accepted Answers : 14
Assignment 12: Programming Assignment 1 - Candies
Questions and their answers will written soon.
Assignment 12: Programming Assignment 2 - Suitcases
Questions and their answers will written soon.
Assignment 12: Programming Assignment 3 - Game of Strengths
Questions and their answers will written soon.
0 Comments
If you have any doubt. Let me know.