The Joy of Computing using Python Week 6 Assignment

                     

Course name: The Joy of Computing Using Python

Link to Enroll: Click here

This is an assignment for The Joy of Computing using Python Week 6 Assignment


Q1. In the list L = [4,6,7,4,6,2,1], What is the index of element ‘7’?
a. 0
b. 1
c. 2
d. 3

Answer: c


Q2. Which of the following is true about recursion?
a. Recursion always performs better than non-recursive code.
b. Recursive code is easier to debug
c. The base case is necessary for recursion.
d. Recursive code can be shorter than non-recursive code.

Answer: b, c, d


This is an assignment for The Joy of Computing using Python Week 6 Assignment


Q3. What will be the output of the following program?

Answer: b


Q4. What will be the output of the following program?

Answer: a


Q5. What’s the correct code for Binary search?

Answer: c


This is an assignment for The Joy of Computing using Python Week 6 Assignment


Q6. Which of the following can be used to see the dimension of a NumPy array named ‘arr’?
a. dim(arr)
b. shape(arr)
c. arr.shape
d. arr.shape()

Answer: c


Q7. If PYTHON is encoded by TCXLSR then DIAMOND will be encoded as?
a. EJBNPOE
b. FKCORPF
c. HMERTSH
d. HMEQSRH

Answer: d


This is an assignment for The Joy of Computing using Python Week 6 Assignment


8. Select the correct statement
1) print(‘9a’.isalnum()) will return True.
2) ‘9a’ contains both alphabetic and numeric parts.

a. Option 1 is correct, option 2 is correct. Option 2 is the correct explanation for option 1.
b. Option 1 is correct, option 2 is incorrect.
c. Option 1 is correct, option 2 is correct. Option 2 is not the correct explanation for option 1.
d. Option 1 is incorrect, option 2 is incorrect.

Answer: a


Q9. What will be the output of the following program?
a. A dictionary with the count of each character in s.
b. A dictionary with the count of each special character in s.
c. A dictionary with the count of letters in s.
d. Error

Answer: d


This is an assignment for The Joy of Computing using Python Week 6 Assignment


Q10. Let L be a list containing different names of movies. Which statement is correct to select a random movie name from that list L?
a. random.choices(L)
b. random.select(L)
c. random.movie(L)
d. random.random(L)

Answer: a


Programming Assignment Questions

Question 1
Given a list L containing integers, write a program that creates and prints a dictionary ‘d’ containing all the numbers that occur twice or more in the list as keys and their indexes as values. Both the keys are and their values should be in the same order as given the list.
You have to take the input.
Input
List
Output
Dictionary D

Solution:

inputList = list(map(int,input().split()))

dict = {}

for i in inputList:
  dict[i] = []

i=0
for j in inputList:
  dict[j].append(i)
  i+=1

res_dict={}

for key,val in dict.items():
  if len(val) >= 2:
    res_dict[key]=val

print(res_dict,end="")

This is an assignment for The Joy of Computing using Python Week 6 Assignment


Question 2
Romeo and Juliet love each other. Romeo wants to send a message to Juliet and also don’t want anyone to read it without his permission. So he shifted every small letter in the sentence by -2 position and every capital letter by -3 position. (If the letter is c, after shifting to by -2 position it changes to a, and for D new letter will be A).
But the letter is too long and Romeo does not have enough time to encrypt his whole letter. Write a program to help Romeo which prints the encrypted message. You can assume there are no special characters except spaces and numeric value.
Input
A string S 
Output 
Encrypted string 

Solution:

S = input()
import string


low = string.ascii_lowercase
cap = string.ascii_uppercase

ans  = ''

for i in S:
    if i in low:
        index = low.index(i)
        # 1-2 = -1+26 = 25
        index = ((index-2)+26)%26
        ans+=low[index]
    elif i in cap:
        index = cap.index(i)
        # 1-2 = -1+26 = 25
        index = ((index-3)+26)%26
        ans+=cap[index]
    else:
        ans+=i

print(ans,end="")

This is an assignment for The Joy of Computing using Python Week 6 Assignment


Question 3
Take a string S as an input and print ‘palindrome’ if string S is a palindrome or ‘not palindrome’ if string S is not a palindrome.
A palindrome is a word which spells same from forward and backward. Example DAD.
Input 
A string S
Output:
palindrome or not palindrome

Solution:

inputString = input()

inputString=inputString.lower()

if inputString[::-1]==inputString:
  print('palindrome',end="")

elif inputString[::-1]!=inputString:
  print('not palindrome',end="")

This is an assignment for The Joy of Computing using Python Week 6 Assignment

More Weeks solutions of this course: https://progies.in/answers/nptel/the-joy-of-computing-using-python

More NPTEL Solution: https://progies.in/answers/nptel


* The material and content uploaded on this website are for general information and reference purposes only. Please do it by your own first.


This is an assignment for The Joy of Computing using Python Week 6 Assignment