The Joy of Computing using Python NPTEL Week 6 Programming Assignment Solution 2021 February
Programming Assignment 1:
Week 6 Programming Assignment 1 Due on 2021-03-04, 23:59 IST
Number Triangle-2
Given an integer input 'n', print a palindromic number triangle of n lines as shown in the example.
Input Format
The input contains a number n (n < 10)
Output Format
Print n lines corresponding to the number triangle
Example:
Input:
5
Output:
1
121
12321
1234321
123454321
Solution:
n=int(input())
for i in range(1,n+1):
for j in range(1,i+1):
print(j,end="")
if i==j:
for k in range(i-1,0,-1):
print(k,end="")
if i!=n:
print("")
Before copy next solution please Click HERE to Subscribe our youtube channel for more solutions.
Programming Assignment 2:
Week 6 Programming Assignment 2 Due on 2021-03-04, 23:59 IST
Anagrams
Given two strings as input, determine if they are anagrams are 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
Solutions:
(s1,s2,x,w)=(input(),input(),[],[])
R=sorted(list(s1.upper()))
S=sorted(list(s2.upper()))
for f in R:
if f.isalnum():
w.append(f)
for f in S:
if f.isalnum():
x.append(f)
if x==w:
print("Yes",end="")
else:
print("No",end="")
Before copy next solution please Click HERE to Subscribe our youtube channel for more solutions.
Programming Assignment 3:
Week 6 Programming Assignment 3 Due on 2021-03-04, 23:59 IST
Break the Secret
You are hired by a secret service agency. Your job is to decode messages. You figure out the algorithm used to encrypt messages and it turns out to be as follows:
The message will consist of only uppercase alphabets. The positional values are assigned to the characters as A=0, B=1, ..., Y=24 and Z=25. In the original message, a character at position i is replaced by a character using the shift formula (i+3)%26.
For example A will be replaced by D, B by E an so on. After replacement, the string is reversed and sent as a message.
You are required to decode this message through your code.(Assuming No Space in the message)
Input Format
A single line of the input contains the encrypted message
Output Format
Print a string containing the original message after decoding
Example:
Input
HBEGRRJ
Output:
GOODBYE
Solutions:
(s,a,b,c)=(input(),"","","")
for i in list(s):
a=a+chr((ord(i)-65+3)%26+65)
for g in list(a)[::-1]:
b=b+g
for t in list(b):
if t=='A':
c=c+'U'
elif t=='B':
c=c+'V'
elif t=='C':
c=c+'W'
elif t=='D':
c=c+'X'
elif t=='E':
c=c+'Y'
elif t=='F':
c=c+'Z'
else:
c=c+chr(ord(t)-6)
print(c,end="")
Please SUBSCRIBE our YouTube Channel.
0 Post a Comment:
Post a Comment
Please do not enter any spam link in the comment box