JOY OF PYTHON USING COMPUTING


Programming Assignments-1: Addition

In this assignment, you will have to take two numbers (integers) as input and print the addition.

Input Format:

The first line of the input contains two numbers separated by a space.

Output Format:
Print the addition in single line

Example:
Input:
4 2

Output:
6

Explanation:
Since the addition of numbers 4 and 2 is 6, hence the output is 6.

Private Test cases used for evaluationInputExpected OutputActual OutputStatus
Test Case 1
100 100
200
200
Passed
Test Case 2
5 10
15
15
Passed
Test Case 3
5 12
17
17
Passed
Test Case 4
8 4
12
12
Passed
.
4 out of 4 tests passed.
You scored 100.0/100.

PROGRAM:

a,b=input().split()
c=int(a)+int(b)
print(c,end="")

       OR
x,y = input().split(" ")
x = int(x)
y = int(y)
print(x+y)

Programming Assignment-2: Small

Given two numbers (integers) as input, print the smaller number.

Input Format:
The first line of input contains two numbers separated by a space

Output Format:
Print the smaller number

Example:

Input:
2 3

Output:
2
Private Test cases used for evaluationInputExpected OutputActual OutputStatus
Test Case 1
100 10
10
10
Passed
Test Case 2
0 1
0
0
Passed
Test Case 3
10 9
9
9
Passed
Test Case 4
9 6
6
6
Passed

4 out of 4 tests passed.
You scored 100.0/100.

PROGRAM:

a,b=input().split()
c=int(a)
d=int(b)
if(c>d):
  print(d,end="")
if(d>c):
  print(c,end="")

        OR

x,y = input().split(" ")

x = int(x)
y = int(y)

if(x<y):
    print(x)
else:
    print(y)

Programming Assignment-3: Loops ,List and Sum

You all have seen how to write loops in python. Now is the time to implement what you have learned.

Given an array A of N numbers (integers), you have to write a program which prints the sum of the elements of array A with the corresponding elements of the reverse of array A.
If array A has elements [1,2,3], then reverse of the array A will be [3,2,1] and the resultant array should be [4,4,4].

Input Format:

The first line of the input contains a number N representing the number of elements in array A.
The second line of the input contains N numbers separated by a space. (after the last elements, there is no space)

Output Format:

Print the resultant array elements separated by a space. (no space after the last element)

Example:

Input:
4
2 5 3 1

Output:
3 8 8 3

Explanation:
Here array A is [2,5,3,1] and reverse of this array is [1,3,5,2] and hence the resultant array is [3,8,8,3]


Private Test cases used for evaluationInputExpected OutputActual OutputStatus
Test Case 1
5
4 3 2 1 3
7 4 4 4 7
7 4 4 4 7 
Passed
Test Case 2
8
1 1 11 1 1 1 1 1
2 2 12 2 2 12 2 2
2 2 12 2 2 12 2 2 
Passed
Test Case 3
3
3 2 1
4 4 4
4 4 4 
Passed
Test Case 4
1
1
2
2 
Passed


4 out of 4 tests passed.
You scored 100.0/100.

PROGRAM:

N=int(input())
A=[int(i) for i in input().split(" ")]
B=[]
for i in range(len(A)-1,-1,-1):
  B.append(A[i])
C=[]
for i in range(len(B)):
  C.append(A[i]+B[i])
for i in range(len(C)):
  if(i==len(C)-1):
    print(C[i],end=" ")
  else: 
    print(C[i],end=" ")

Programming Assignment-1: Max and Min

Given a list of numbers (integers), find second maximum and second minimum in this list.

Input Format:

The first line contains numbers separated by a space.

Output Format:

Print second maximum and second minimum separated by a space

Example:

Input:

1 2 3 4 5

Output:

4 2


Private Test cases used for evaluationInputExpected OutputActual OutputStatus
Test Case 1
10 10
10 10
10 10
Passed
Test Case 2
1 1 1 1
1 1
1 1
Passed
Test Case 3
1 2 3 4 5 6 7 8
7 2
7 2
Passed
Test Case 4
1 2
1 2
1 2
Passed


4 out of 4 tests passed.
You scored 100.0/100.

PROGRAM:

list1=list(map(int,input().split()))
list1.sort()
#list1=list(dict.fromkeys(list1))
length=len(list1)
print(list1[length-2],list1[1],end="")
   
                    OR

a = [int(x) for x in input().split()]

a.sort() #this command sorts the list in ascending order

print(a[-2],a[1])

Programming Assignment-2: Multiple of 5

Given a list A of numbers (integers), you have to print those numbers which are not multiples of 5.

Input Format:

The first line contains the numbers of list A separated by a space.

Output Format:

Print the numbers in a single line separated by a space which are not multiples of 5.

Example:

Input:

1 2 3 4 5 6 5

Output:

1 2 3 4 6

Explanation:
Here the elements of A are 1,2,3,4,5,6,5 and since 5 is the multiple of 5, after removing them the list becomes 1,2,3,4,6.


Private Test cases used for evaluationInputExpected OutputActual OutputStatus
Test Case 1
87 34 12 90 34 23 98 67 12 23
87 34 12 34 23 98 67 12 23
87 34 12 34 23 98 67 12 23
Passed
Test Case 2
23 87 56 34 12 61 58 64 29 98 2 16 2 6 9
23 87 56 34 12 61 58 64 29 98 2 16 2 6 9
23 87 56 34 12 61 58 64 29 98 2 16 2 6 9
Passed
Test Case 3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 15 16 17 18 19
1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19
1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19
Passed


3 out of 3 tests passed.
You scored 100.0/100.
PROGRAM:

list1=list(map(int,input().split()))
list2= []
for i in list1:
  if i%5!=0:
    list2.append(i)
print(*list2,end="")
  
          OR
a = [int(x) for x in input().split()]

b = []

for i in a:
    if(i%5!=0):
        b.append(i)

for i in range(len(b)):
    if(i==len(b)-1):
        print(b[i],end="")
    else:
        print(b[i],end=" ")

Programming Assignment-3: Digits

You are given a number A which contains only digits 0's and 1's. Your task is to make all digits same by just flipping one digit (i.e. 0 to 1 or 1 to 0 ) only. If it is possible to make all the  digits same by just flipping one digit then print 'YES' else print 'NO'.

Input Format:

The first line contains a number made up of 0's and 1's.

Output Format:

Print 'YES' or 'NO' accordingly without quotes.

Example:

Input:

101

Output:
YES

Explanation:
If you flip the middle digit from 0 to 1 then all the digits will become same. Hence output is YES.
Private Test cases used for evaluationInputExpected OutputActual OutputStatus
Test Case 1
11
NO
NO
Passed
Test Case 2
10
YES
YES
Passed
Test Case 3
0
YES
YES
Passed

3 out of 3 tests passed.
You scored 100.0/100.

PROGRAM:


list1=input()

#print(list1)
x=list1.count('1')
y=list1.count('0')
l=len(list1)
#print(x,y,l)
if x==l-1 and y==1:
  print("YES",end='')
elif x==1 and y==l-1:
  print("YES",end="")
else:
  print("NO",end="")

           OR
A = input()
ls = []
li = str(A)
for j in li:
    ls.append(int(j))
count_z = 0
count_o = 0
for k in ls:
    if(k==1):
        count_o += 1
    if(k==0):
        count_z += 1

if((count_o == 1) or (count_z == 1)):
    print("YES")

else:
    if((count_o == 0) or (count_z == 0)):
        print("NO")
    else:
        print("NO")

Programming Assignment-1: Factorial


Given an integer number n, you have to print the factorial of this number. To know about factorial please click on this link.

Input Format:

A number n.

Output Format:

Print the factorial of n.

Example:
Input:
4

Output:
24

Private Test cases used for evaluationInputExpected OutputActual OutputStatus
Test Case 1
8
40320
40320
Passed
Test Case 2
7
5040
5040
Passed
Test Case 3
10
3628800
3628800
Passed

3 out of 3 tests passed.
You scored 100.0/100.
PROGRAM:


n=input()

num=int(n)
factorial=1
if num==0:
  print("The factorial of 0 is 1")
else:
  for i in range(1,num+1):
    factorial=factorial*i
  print(factorial,end="")

              OR
k = int(input())

fac = 1
for i in range(1,k+1):
    if(k==0):
        break
    fac=fac*i

print(fac)

Programming Assignment-2: Matrix

You are provided with the number of rows (R) and columns (C). Your task is to generate the matrix having R rows and C columns such that all the numbers are in increasing order starting from 1 in row wise manner.

Input Format:
The first line contain two numbers R and C separated by a space.

Output Format:
Print the elements of the matrix with each row in a new line and elements of each row are separated by a space.

NOTE: There should not be any space after the last element of each row and no new line after the last row.

Example:

Input:
3 3

Output:
1 2 3
4 5 6
7 8 9

Explanation:
Starting from the first row, the numbers are present in the increasing order. Since it's a 3X3 matrix, the numbers are from 1 to 9.


Private Test cases used for evaluationInputExpected OutputActual OutputStatus
Test Case 1
4 4
1 2 3 4\n
5 6 7 8\n
9 10 11 12\n
13 14 15 16
1 2 3 4\n
5 6 7 8\n
9 10 11 12\n
13 14 15 16
Passed
Test Case 2
5 5
1 2 3 4 5\n
6 7 8 9 10\n
11 12 13 14 15\n
16 17 18 19 20\n
21 22 23 24 25
1 2 3 4 5\n
6 7 8 9 10\n
11 12 13 14 15\n
16 17 18 19 20\n
21 22 23 24 25
Passed
Test Case 3
10 10
1 2 3 4 5 6 7 8 9 10\n
11 12 13 14 15 16 17 18 19 20\n
21 22 23 24 25 26 27 28 29 30\n
31 32 33 34 35 36 37 38 39 40\n
41 42 43 44 45 46 47 48 49 50\n
51 52 53 54 55 56 57 58 59 60\n
61 62 63 64 65 66 67 68 69 70\n
71 72 73 74 75 76 77 78 79 80\n
81 82 83 84 85 86 87 88 89 90\n
91 92 93 94 95 96 97 98 99 100
1 2 3 4 5 6 7 8 9 10\n
11 12 13 14 15 16 17 18 19 20\n
21 22 23 24 25 26 27 28 29 30\n
31 32 33 34 35 36 37 38 39 40\n
41 42 43 44 45 46 47 48 49 50\n
51 52 53 54 55 56 57 58 59 60\n
61 62 63 64 65 66 67 68 69 70\n
71 72 73 74 75 76 77 78 79 80\n
81 82 83 84 85 86 87 88 89 90\n
91 92 93 94 95 96 97 98 99 100
Passed


3 out of 3 tests passed.
You scored 100.0/100.

PROGRAM:

r,c=input().split(" ")
r=int(r)
c=int(c)
mat=[[0 for i in range(c)]for j in range(r)]
val=1
for i in range(r):
  for j in range(c):
    mat[i][j]=val
    val=val+1
for i in range(r):
  for j in range(c):
    if j!=(c-1):
      print(mat[i][j],end=" ")
    else:
      print(mat[i][j],end="")
  if i!=(r-1):
    print()

               OR
a,b=map(int,input().split())

count=1
m = []
for i in range(1,a+1):
    l = []
    for j in range(1,b+1):
        l.append(count)
        count+=1
    m.append(l)

for i in range(a):
    for j in range(b):
        if(j==b-1):
            print(m[i][j], end="")
        else:
            print(m[i][j], end=" ")
    if(i!=a-1):
        print()

Programming Assignment-3: The power of Randomness

You all have used the random library of python. You have seen in the screen-cast of how powerful it is.
In this assignment, you will sort a list let's say list_1 of numbers in increasing order using the random library.

Following are the steps to sort the numbers using the random library.

Step 1: Import the randint definition of the random library of python. Check this page if you want some help.

Step 2: Take the elements of the list_1 as input.

Step 3: randomly choose two indexes i and j within the range of the size of list_1.

Step 4: Swap the elements present at the indexes i and j. After doing this, check whether the list_1 is sorted or not.

Step 5: Repeat step 3 and 4 until the array is not sorted.

Input Format:
The first line contains a single number n which signifies the number of elements in the list_1.
From the second line, the elements of the list_1 are given with each number in a new line.

Output Format:
Print the elements of the list_1 in a single line with each element separated by a space. 
NOTE 1: There should not be any space after the last element.

Example:

Input:
4
3
1
2
5

Output:
1 2 3 5

Explanation: 
The first line of the input is 4. Which means that n is 4, or the number of elements in list_1 is 4. The elements of list_1 are 3, 1, 2, 5 in this order.
The sorted version of this list is 1 2 3 5, which is the output.

NOTE 2: There are many ways to sort the elements of a list. The purpose of this assignment is to show the power of randomness, and obviously it's fun.


Private Test cases used for evaluationInputExpected OutputActual OutputStatus
Test Case 1
6
6
4
3
2
1
1
1 1 2 3 4 6
1 1 2 3 4 6
Passed
Test Case 2
5
5
4
3
2
1
1 2 3 4 5
1 2 3 4 5
Passed
Test Case 3
3
5
1
6
1 5 6
1 5 6
Passed


3 out of 3 tests passed.
You scored 100.0/100.

PROGRAM:

from random import randint
n= int(input())
I=[]
for i in range(n):
  ip=int(input())
  I.append(ip)
S=True
u=sorted(I)
while(S):
  j=randint(0,n-1)
  i=randint(0,n-1)
  ab=I[j]
  I[j]=I[i]
  I[i]=ab
  if I==u:
    S=True
  else:
    S=False
  if(S):
    break
  else:
    S=True
for b in range(n):
  if(b==n-1):
    print(I[b],end="")
  else:
    print(I[b],end=" ")



                OR




from random import randint
n = int(input())
arr = []
for i in range(n):
    x = int(input())
    arr.append(x)

sorted = True

while(sorted):
    j = randint(0,n-1)
    i = randint(0,n-1)
    arr[i],arr[j] = arr[j],arr[i]
    for k in range(0,n-1):
        if (arr[k] > arr[k+1]):
            sorted = False
   
    if(sorted):
        break
    else:
        sorted = True

for i in range(n):
    if(i==n-1):
        print(arr[i])
    else:
        print(arr[i],end=" ")






Programming Assignment-1: Cab and walk


Arun is working in an office which is N blocks away from his house. He wants to minimize the time it takes him to go from his house to the office.
He can either take the office cab or he can walk to the office.
Arun's velocity is V1 m/s when he is walking. The cab moves with velocity V2 m/s but whenever he calls for the cab, it always starts from the office, covers N blocks, collects Arun and goes back to the office.
The cab crosses a total distance of N meters when going from office to Arun's house and vice versa, whereas Arun covers a distance of (2N) while walking.
Help Arun to find whether he should walk or take a cab to minimize the time.

Input Format:
A single line containing three integer numbers N, V1, and V2 separated by a space.

Output Format:
Print 'Walk' or 'Cab' accordingly

Constraints:

1<=V1, V2 <=100

1<=N<=200

Example-1:

Input:
5 10 15

Output:
Cab

Example-2:

Input:
2 10 14

Output:
Walk

Private Test cases used for evaluation Input Expected Output Actual Output Status
Test Case 1
100 40 60
 Cab
Cab
Passed
Test Case 2
200 50 80
 Cab
Cab
Passed
Test Case 3
100 50 50
 Walk
Walk
Passed

Due Date Exceeded.
3 out of 3 tests passed.

You scored 100.0/100.
PROGRAM:
n,v1,v2=input().split(" ")
n,v1,v2=int(n),int(v1),int(v2)
tv1=(2**.5*n/v1)
tv2=(2*n/v2)
if(tv1>tv2):
  print("Cab",end="")
else:
  print("Walk",end="")



                    OR 

n,v1,v2 = input().split()

n = int(n)
v1 = int(v1)
v2 = int(v2)

st_d = pow(2,1/2)*n
st_t = st_d/v1

el_d = 2*n
el_t = el_d/v2

if(st_t<el_t):
    print("Walk")
else:
    print("Cab")



Programming Assignment-2: End-Sort

Due on 2019-09-05, 23:59 IST
Given a list A of N distinct integer numbers, you can sort the list by moving an element to the end of the list. Find the minimum number of moves required to sort the list using this method in ascending order. 

Input Format:
The first line of the input contains N distinct integers of list A separated by a space.

Output Format
Print the minimum number of moves required to sort the elements.

Example:

Input:
1 3 2 4 5

Output:
3

Explanation:
In the first move, we move 3 to the end of the list. In the second move, we move 4 to the end of the list, and finally, in the third movement, we move 5 to the end.
Private Test cases used for evaluation Input Expected Output Actual Output Status
Test Case 1
20 3 1 2 6 7 8 21 19 5
8
8
Passed
Test Case 2
4 1 3 5 6 2 7 9 8
7
7
Passed
Test Case 3
1 2 3 4 5 6 7 8 9 15 14 13 12 11 10
5
5
Passed

Due Date Exceeded.
3 out of 3 tests passed.
You scored 100.0/100.

Programming Assignment-2: End-Sort


Given a list A of N distinct integer numbers, you can sort the list by moving an element to the end of the list. Find the minimum number of moves required to sort the list using this method in ascending order. 

Input Format:
The first line of the input contains N distinct integers of list A separated by a space.

Output Format
Print the minimum number of moves required to sort the elements.

Example:

Input:
1 3 2 4 5

Output:
3

Explanation:
In the first move, we move 3 to the end of the list. In the second move, we move 4 to the end of the list, and finally, in the third movement, we move 5 to the end.
Private Test cases used for evaluation Input Expected Output Actual Output Status
Test Case 1
20 3 1 2 6 7 8 21 19 5
8
8
Passed
Test Case 2
4 1 3 5 6 2 7 9 8
7
7
Passed
Test Case 3
1 2 3 4 5 6 7 8 9 15 14 13 12 11 10
5
5
Passed

Due Date Exceeded.
3 out of 3 tests passed.
You scored 100.0/100.
PROGRAM:

x=[int(x) for x in input().split()]
x1=sorted(x)
c=0
for i in range(len(x)):
  if x[i]==x1[c]:
    c=c+1
print(len(x)-c,end="")

            OR 

arr = [int(x) for x in input().split()]
arr1 = sorted(arr)
count = 0
for i in range(len(arr)):
    if arr[i] == arr1[count]:
        count+=1
print(len(arr)-count)

Programming Assignment-3: Semi Primes


A semiprime number is an integer which can be expressed as a product of two distinct primes. For example 15 = 3*5 is a semiprime number but 9 = 3*3 is not .
Given an integer number N, find whether it can be expressed as a sum of two semi-primes or not (not necessarily distinct).

Input Format:
The first line contains an integer N.

Output Format:
Print 'Yes' if it is possible to represent N as a sum of two semiprimes 'No' otherwise.

Example:
Input:
30

Output:
Yes

Explanation:
N = 30 can be expressed as 15+15 where 15 is a semi-prime number (5*3 = 15)

NOTE: N is less than equal to 200
Private Test cases used for evaluation Input Expected Output Actual Output Status
Test Case 1
123
Yes
Yes
Passed
Test Case 2
58
No
Yes
Wrong Answer
Test Case 3
158
Yes
No
Wrong Answer

Due Date Exceeded.
1 out of 3 tests passed.
You scored 33.3333333333/100.

PROGRAM:

prime1=[]
prime2=[]
semiprime1=[]
semiprime2=[]
last=[]
n=int(input())
for i in range(2,n):
  for j in range(2,i):
    if(i%j==0):
      break
    else:
      prime1.append(i)
      prime2.append(i)
for i in prime1:
  for j in prime2:
    if i!=j and i*j<=n:
      semiprime1.append(i*j)
      semiprime2.append(i*j)
semiprime1.sort()
semiprime2.sort()
for i in semiprime1:
  for j in semiprime2:
    if(i+j<=n):
      if(i+j) not in last:
        last.append(i+j)
last.sort()
if n in last:
  print("No",end="")
else:
  print("Yes",end="")
 

             OR 

li = [12, 16, 20, 21, 24, 25, 27, 28, 29, 30, 31, 32, 35, 36, 37, 39, 40, 41, 42, 43, 44, 45, 47, 48, 49, 50, 52, 53, 54, 55, 56, 57, 59, 60, 61, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200]

N = int(input())
if (N in li):
    print('Yes')
else:
    print('No')


Programming Assignment-1: Computing Paradox


You are provided with a playlist containing N songs, each has a unique positive integer length. Assume you like all the songs from this playlist, but there is a song, which you like more than others.
It is named "Computing Paradox".

You decided to sort this playlist in increasing order of songs length. For example, if the lengths of the songs in the playlist were {1, 3, 5, 2, 4} after sorting it becomes {1, 2, 3, 4, 5}.
Before the sorting, "Computing Paradox" was on the kth position (1-indexing is assumed for the playlist) in the playlist.

Your task is to find the position of "Computing Paradox" in the sorted playlist.

Input Format:
The first line contains two numbers N denoting the number of songs in the playlist.
The second line contains N space separated integers A1, A2, A3,..., AN denoting the lengths of songs.
The third line contains an integer k, denoting the position of "Computing Paradox" in the initial playlist.

Output Format:

Output a single line containing the position of "Computing Paradox" in the sorted playlist.

Example:

Input:
4
1 3 4 2
2


Output:

3

Explaination:
N equals to 4, k equals to 2, A equals to {1, 3, 4, 2}. The answer is 3 because {1, 3, 4, 2} -> {1, 2, 3, 4}.
Private Test cases used for evaluation Input Expected Output Actual Output Status
Test Case 1
16
11 22 33 21 47 37 23 14 32 2 3 1 6 45 24 16
1
5
5
Passed
Test Case 2
6
1 2 3 4 5 7
6
6
6
Passed
Test Case 3
6
39 45 7 24 30 32
3
1
1
Passed

Due Date Exceeded.
3 out of 3 tests passed.
You scored 100.0/100.
PROGRAM:
t=int(input())
a=[int(i) for i in input().split()]
f=int(input())
b=sorted(a)
x=a[f-1]
print(b.index(x)+1,end="")
               OR
n=int(input())
a=[int(x) for x in input().split()]
k=int(input())
key=a[k-1]
a.sort()
for i in range(len(a)):
    if key==a[i]:
        print(i+1)
        break

Programming Assignment-2: Dictionary


Given a positive integer number n, you have to write a program that generates a dictionary d which contains (i, i*i*i) such that i is the key and i*i*i is its value, where i is from 1 to n (both included).
Then you have to just print this dictionary d.

Example:
Input: 4

will give output as
{1: 1, 2: 8, 3: 27, 4: 64}

Input Format:
Take the number n in a single line.

Output Format:
Print the dictionary d in a single line.


Example:

Input:
8

Output:
{1: 1, 2: 8, 3: 27, 4: 64, 5: 125, 6: 216, 7: 343, 8: 512}

Explanation:

Here n is 8, we will start from i=1, hence the first element of the dictionary is (1: 1), as i becomes 2, the second element of the dictionary becomes (2: 8) and so on.
Hence the output will be {1: 1, 2: 8, 3: 27, 4: 64, 5: 125, 6: 216, 7: 343, 8: 512}.
Private Test cases used for evaluation Input Expected Output Actual Output Status
Test Case 1
12
{1: 1, 2: 8, 3: 27, 4: 64, 5: 125, 6: 216, 7: 343, 8: 512, 9: 729, 10: 1000, 11: 1331, 12: 1728}
{1: 1, 2: 8, 3: 27, 4: 64, 5: 125, 6: 216, 7: 343, 8: 512, 9: 729, 10: 1000, 11: 1331, 12: 1728}
Passed
Test Case 2
15
{1: 1, 2: 8, 3: 27, 4: 64, 5: 125, 6: 216, 7: 343, 8: 512, 9: 729, 10: 1000, 11: 1331, 12: 1728, 13: 2197, 14: 2744, 15: 3375}
{1: 1, 2: 8, 3: 27, 4: 64, 5: 125, 6: 216, 7: 343, 8: 512, 9: 729, 10: 1000, 11: 1331, 12: 1728, 13: 2197, 14: 2744, 15: 3375}
Passed
Test Case 3
25
{1: 1, 2: 8, 3: 27, 4: 64, 5: 125, 6: 216, 7: 343, 8: 512, 9: 729, 10: 1000, 11: 1331, 12: 1728, 13: 2197, 14: 2744, 15: 3375, 16: 4096, 17: 4913, 18: 5832, 19: 6859, 20: 8000, 21: 9261, 22: 10648, 23: 12167, 24: 13824, 25: 15625}
{1: 1, 2: 8, 3: 27, 4: 64, 5: 125, 6: 216, 7: 343, 8: 512, 9: 729, 10: 1000, 11: 1331, 12: 1728, 13: 2197, 14: 2744, 15: 3375, 16: 4096, 17: 4913, 18: 5832, 19: 6859, 20: 8000, 21: 9261, 22: 10648, 23: 12167, 24: 13824, 25: 15625}
Passed

Due Date Exceeded.
3 out of 3 tests passed.
You scored 100.0/100.
PROGRAM:
t=int(input())
a=[i for i in range(1,t+1)]
a2=[i**3 for i in range(1,t+1)]
x=dict(zip(a,a2))
print(x,end="")
         OR

n=int(input())
d=dict()
for i in range(1,n+1):
    d[i]=i*i*i

print(d)

Programming Assignment-3: Functions


Given an integer number n, define a function named printDict() which can print a dictionary where the keys are numbers between 1 and n (both included) and the values are square of keys.
The function printDict() doesn't take any argument.

Input Format:
The first line contains the number n.

Output Format:
Print the dictionary in one line.

Example:

Input:
5

Output:
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25}

NOTE: You are supposed to write the code for the function printDict() only. The function has already been called in the main part of the code.
Private Test cases used for evaluation Input Expected Output Actual Output Status
Test Case 1
16
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100, 11: 121, 12: 144, 13: 169, 14: 196, 15: 225, 16: 256}
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100, 11: 121, 12: 144, 13: 169, 14: 196, 15: 225, 16: 256}
Passed
Test Case 2
6
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36}
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36}
Passed
Test Case 3
13
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100, 11: 121, 12: 144, 13: 169}
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100, 11: 121, 12: 144, 13: 169}
Passed

Due Date Exceeded.
3 out of 3 tests passed.
You scored 100.0/100.
PROGRAM:
def printDict():
  x=int(input())
  d={}
  for i in range(x):
    d[i+1]=(i+1)**2
  print(d,end='')
printDict()

printDict()
          OR
def printDict():
    n = int(input())
    d=dict()
    for i in range(1,n+1):
        d[i]=i**2
    print(d)
printDict()

Programming Assignment-1: Lower Triangular Matrix


Lower triangular matrix is a square matrix (where the number of rows and columns are equal)  where all the elements above the diagonal are zero.
For example, the following is an upper triangular matrix with the number of rows and columns equal to 3.

1 0 0
4 5 0
7 8 9

Write a program to convert a square matrix into a lower triangular matrix.

Input Format:The first line of the input contains an integer number n which represents the number of rows and the number of columns.
From the second line, take n lines input with each line containing n integer elements. Elements are separated by space.

Output format:
Print the elements of the matrix with each row in a new line and each element separated by a space.

Example 1:

Input:
3
1 2 3
4 5 6
7 8 9

Output:
1 0 0
4 5 0
7 8 9

Example 2:

Input:
4
12 2 5 6
10 11 4 1
32 1 4 10
1 2 10 9

Output:
12 0 0 0
10 11 0 0
32 1 4 0
1 2 10 9

Explanation:
In both the examples, elements which are above the diagonal are zero.

NOTE: There should not be any extra space after the elements of the last column and no extra newline after the last row of the matrix.
Private Test cases used for evaluation Input Expected Output Actual Output Status
Test Case 1
7
16 9 16 15 7 42 47
17 39 14 28 48 4 1
29 36 5 13 13 45 50
34 34 13 18 20 27 41
37 23 16 24 32 35 19
28 13 40 1 29 36 50
37 22 42 22 43 40 48
16 0 0 0 0 0 0\n
17 39 0 0 0 0 0\n
29 36 5 0 0 0 0\n
34 34 13 18 0 0 0\n
37 23 16 24 32 0 0\n
28 13 40 1 29 36 0\n
37 22 42 22 43 40 48
16 0 0 0 0 0 0\n
17 39 0 0 0 0 0\n
29 36 5 0 0 0 0\n
34 34 13 18 0 0 0\n
37 23 16 24 32 0 0\n
28 13 40 1 29 36 0\n
37 22 42 22 43 40 48
Passed
Test Case 2
3
7 0 0
48 46 0
16 28 46
7 0 0\n
48 46 0\n
16 28 46
7 0 0\n
48 46 0\n
16 28 46
Passed
Test Case 3
4
1 0 0 0
5 6 0 0
9 10 11 0
13 14 15 16
1 0 0 0\n
5 6 0 0\n
9 10 11 0\n
13 14 15 16
1 0 0 0\n
5 6 0 0\n
9 10 11 0\n
13 14 15 16
Passed

Due Date Exceeded.
3 out of 3 tests passed.
You scored 100.0/100.
PROGRAM:
n=int(input())
l=[]
for i in range(n):
  for j in range(1):
    temp=[int(g) for g in input().split()]
    l.append(temp)
for i in range(n):
  for j in range(n):
    if i<j:
      if j==n-1:
        print("0",end="")
      else:
        print("0",end=" ")
    else:
      if j==n-1:
        print(l[i][j],end="")
      else:
        print(l[i][j],end=" ")
       
  if i!=n-1:
    print()
     
       
                    OR
a = int(input())


m = []
for i in range(1,a+1):   
    l = list(map(int, input ().split ()))
    m.append(l)

for i in range(a):
    for j in range(a):
        if(i>=j):
            if(j==a-1):
                print(m[i][j], end="")
            else:
                print(m[i][j], end=" ")
        else:
            if(j==a-1):
                print(0, end="")
            else:
                print(0, end=" ")
    if(i!=a-1):
        print()

Programming Assignment-2: Symmetric

Due on 2019-09-19, 23:59 IST
Given a square matrix of N rows and columns, find out whether it is symmetric or not.

Input Format:The first line of the input contains an integer number n which represents the number of rows and the number of columns.
From the second line, take n lines input with each line containing n integer elements with each element separated by a space.

Output Format:
Print 'YES' if it is symmetric otherwise 'NO'

Example:

Input:
2
1 2
2 1

Output:
YES
Private Test cases used for evaluation Input Expected Output Actual Output Status
Test Case 1
3
5 6 7
6 3 2
7 2 1
YES
YES
Passed
Test Case 2
1
1
YES
YES
Passed
Test Case 3
3
1 3 2
2 3 1
1 2 2
NO
NO
Passed

Due Date Exceeded.
3 out of 3 tests passed.
You scored 100.0/100.
PROGRAM:
n=int(input())
l=[]
for i in range(n):
  for j in range(1):
    temp=[int(g) for g in input().split()]
    l.append(temp)
x=0
for i in range(n):
  for j in range(n):
    if l[i][j]!=l[j][i]:
      x=x+1
if x==0:
  print("YES",end="")
else:
  print("NO",end="")
 
             OR
def isSymmetric(mat, N):
    for i in range(N):
        for j in range(N):
            if (mat[i][j] != mat[j][i]):
                return False
    return True
  

a = int(input())


m = []
for i in range(1,a+1):   
    l = list(map(int, input ().split ()))
    m.append(l)
if (isSymmetric(m, a)):
    print("YES")
else:
    print("NO")

Programming Assignment-3: Binary Matrix


Given a matrix with N rows and M columns, the task is to check if the matrix is a Binary Matrix. A binary matrix is a matrix in which all the elements are either 0 or 1.

Input Format:The first line of the input contains two integer number N and M which represents the number of rows and the number of columns respectively, separated by a space.
From the second line, take N lines input with each line containing M integer elements with each element separated by a space.

Output Format:
Print 'YES' or 'NO' accordingly

Example:

Input:
3 3
1 0 0
0 0 1
1 1 0

Output:
YES
Private Test cases used for evaluation Input Expected Output Actual Output Status
Test Case 1
5 3
1 2 3
4 5 6
7 8 9
1 0 0
1 1 1
NO
NO
Passed
Test Case 2
4 6
1 1 0 0 1 1
1 1 1 1 1 1
0 0 0 0 1 0
1 0 1 0 1 0
YES
YES
Passed
Test Case 3
1 1
0
YES
YES
Passed

Due Date Exceeded.
3 out of 3 tests passed.
You scored 100.0/100.
PROGRAM:
n,m=map(int,input().split())
b=0
for i in range(n):
  for j in range(1):
    temp=[int(g) for g in input().split()]
    for k in temp:
      if k!=0 and k!=1:
        b=b+1
        break
if b==0:
  print("YES",end="")
else:
  print("NO",end="")
    
                  OR
def isBinaryMatrix(mat,M,N):
    for i in range(M):
        for j in range(N):
            # Returns false if element
            # is other than 0 or 1.
            if ((mat[i][j] == 0 or mat[i][j] == 1)==False):
                return False;
 
    # Returns true if all the 
    # elements are either 0 or 1.
    return True;

a,b=map(int,input().split())


m = []
for i in range(1,a+1):   
    l = list(map(int, input ().split ()))
    m.append(l)
if (isBinaryMatrix(m,a,b)):
    print("YES")
else:
    print("NO")

Programming Assignment - 1: Duplicate Elements

Due on 2019-09-25, 23:59 IST
With a given list L of integers, write a program to print this list L after removing all duplicate values with original order preserved.

Example:

If the input list is

12 24 35 24 88 120 155 88 120 155

Then the output should be

12 24 35 88 120 155

Explanation:
Third, seventh and ninth element of the list L has been removed because it was already present.

Input Format:
In one line take the elements of the list L with each element separated by a space.

Output Format:
Print the elements of the modified list in one line with each element separated by a space.

Example:
Input:
12 24 35 24

Output:
12 24 35
Private Test cases used for evaluation Input Expected Output Actual Output Status
Test Case 1
4 3 3 2 2 0 7 6 6 3 9 8 3 0 1 9 0 4 8 7 0 7 5 8 9 4 4 7 6 4 7 2 6 9 1 0 5 9 2 3 3 2 6 8 8 2 2 3 0 3 5 3 1 3 1 1 8 5 2 7 9 0 3 0 4 5 7 4 8 0 7 0 0 1 4 0 8 7 1 7 0 1 6 5 5 7 1 3 8 3 0 9 9
4 3 2 0 7 6 9 8 1 5
4 3 2 0 7 6 9 8 1 5
Passed
Test Case 2
1 8 9 6 0 3 2 1 0 6 2 0 4 1 0 3 7 1 6 5 3 9 9 5 5 0 9 9 1 1 3 8 2 3 4 7 5 2 1 1 5 0 4 3 9 3 0 3 9 4 9 8 2 2 2 2 2
1 8 9 6 0 3 2 4 7 5
1 8 9 6 0 3 2 4 7 5
Passed
Test Case 3
3 2 8 8 0 4 6 4 5 7 0 0 0 7 2 7 4 1 7 0 6 3 1 8 7 7 5 9 9 7 7 4 4 4 5 6 6 6 3 3 2 5 3 1 3 6 8 0 1 5 2 5 0 1 4 2 6 5 7 9 2 2 5 4 0 8 6 4 9 4 9 0 8 4 3 7 5 0 1 4 3 7 8 0 7 3 3 3 8 6 9 4 4 6 6 2 2 5 0 9 3 3 7 9 9 1 0 6 9 9 3 3 7 5 3 4 2 0 3 0 1 7 6 8 8 5 5
3 2 8 0 4 6 5 7 1 9
3 2 8 0 4 6 5 7 1 9
Passed

Due Date Exceeded.
3 out of 3 tests passed.
You scored 100.0/100.
PROGRAM:
o=list(map(int,input().split()))
d=[]
for i in o:
  if i not in d:
    d.append(i)
print(*d,end="")
          OR
def removeDuplicate( li ):
    newli=[]
    seen = set()
    for item in li:
        if item not in seen:
            seen.add( item )
            newli.append(item)

    return newli

li=[]
li= list(map(int, input ().split ()))
x = removeDuplicate(li)

for i in x:
    print(i,end=" ")

Programming Assignment-2: Panagrams


A panagram is a sentence containing every 26 letters in the English alphabet. Given a string S, check if it is panagram or not.

Input Format:
The first line contains the sentence S.

Output Format:
Print 'YES' or 'NO' accordingly

Example:

Input:
The quick brown fox jumps over the lazy dog

Output:
YES

Private Test cases used for evaluation Input Expected Output Actual Output Status
Test Case 1
Ghe quick brown fox jumps ovar the lezy doT
YES
YES
Passed
Test Case 2
Ghe quick bxown for jumps ovar the lezy doT
YES
YES
Passed
Test Case 3
abc
NO
NO
Passed

Due Date Exceeded.
3 out of 3 tests passed.
You scored 100.0/100.
PROGRAM:
alphabet=[]
for i in range(97,123):
  alphabet.append(chr(i))
s=input()
s=s.lower()
d=set(s)
d=list(d)
for i in d:
  if i in alphabet:
    alphabet.remove(i)
if len(alphabet)==0:
  print("YES",end="")
else:
  print("NO",end="")
                OR
def checkPangram(s):
    List = []
    # create list of 26 charecters and set false each entry
    for i in range(26):
        List.append(False)
         
    #converting the sentence to lowercase and iterating
    # over the sentence 
    for c in s.lower(): 
        if not c == " ":
            # make the corresponding entry True
            List[ord(c) -ord('a')]=True
             
    #check if any charecter is missing then return False
    for ch in List:
        if ch == False:
            return False
    return True
 
# Driver Program to test above functions
sentence = input()
 
if (checkPangram(sentence)):
    print("YES")
else:
    print("NO")

Programming Assignment-3: Vowels


Given a string S of lowercase letters, remove consecutive vowels from S. After removing, the order of the list should be maintained.

Input Format:

Sentence S in a single line

Output Format:
Print S after removing consecutive vowels

Example:

Input:
your article is in queue

Output:
yor article is in qu

Explanation:

In the first word, 'o' and 'u' are appearing together, hence the second letter 'u' is removed. In the fifth word, 'u', 'e', 'u' and 'e' are appearing together, hence 'e', 'u', 'e' are removed.


Input Output
Test Case 1
neeru neetu and neeraj
neru netu and neraj
Test Case 2
dsabj dsahjlg dfsabdsaeas asdasdasdssaasa ioioeseaeaoi
dsabj dsahjlg dfsabdsas asdasdasdssasa ise
Test Case 3
three four five
thre for five
Test Case 4
great part of life
gret part of life
Test Case 5
eel is electricity
el is electricity
Test Case 6
love hate and war
love hate and war
PROGRAM:

def is_vow(c):
 
    # this compares vowel with 
    # character 'c'
    return ((c == 'a') or (c == 'e') or
            (c == 'i') or (c == 'o') or
            (c == 'u'))
 
# function to print resultant string
def removeVowels(str):
 
    # print 1st character
    print(str[0], end = "")
 
    # loop to check for each character
    for i in range(1,len(str)):
 
        # comparison of consecutive
        # characters
        if ((is_vow(str[i - 1]) != True) or
            (is_vow(str[i]) != True)):
             
            print(str[i], end = "")
 
# Driver code
str= input()
removeVowels(str)

Programming Assignment-1: Counter Spiral


Given a square matrix, you have to write a program to print it in a counter-clockwise spiral form.


Input Format:
The first line of the input contains an integer number n which represents the number of rows and columns in the matrix.
From the second line contains n rows with each row having n elements separated by a space.

Output Format:
Print the elements in a single line with each element separated by a space

Example:

Input:
4
25 1 29 7
24 20 4 32
16 38 29 1
48 25 21 19

Output:
25 24 16 48 25 21 19 1 32 7 29 1 20 38 29 4

Explanation:
In the above example, each row, first all the elements of the first column is printed which are 25 24 16 48 after that, remaining elements of the last row is printed which are 25 21 and 19.
After which the remaining elements of the last column is printed which are 1 32 and 7 and so on...
Private Test cases used for evaluation Input Expected Output Actual Output Status
Test Case 1
9
26 32 29 4 34 39 4 29 24
6 35 34 17 17 17 22 7 43
15 26 30 20 11 40 27 11 32
21 7 26 13 22 50 3 12 8
11 35 41 44 38 29 27 35 20
11 22 19 21 49 43 49 32 16
34 15 44 36 11 26 41 46 12
34 20 41 32 47 23 47 11 25
18 6 46 25 41 39 45 33 16
26 6 15 21 11 11 34 34 18 6 46 25 41 39 45 33 16 25 12 16 20 8 32 43 24 29 4 39 34 4 29 32 35 26 7 35 22 15 20 41 32 47 23 47 11 46 32 35 12 11 7 22 17 17 17 34 30 26 41 19 44 36 11 26 41 49 27 3 27 40 11 20 13 44 21 49 43 29 50 22 38
26 6 15 21 11 11 34 34 18 6 46 25 41 39 45 33 16 25 12 16 20 8 32 43 24 29 4 39 34 4 29 32 35 26 7 35 22 15 20 41 32 47 23 47 11 46 32 35 12 11 7 22 17 17 17 34 30 26 41 19 44 36 11 26 41 49 27 3 27 40 11 20 13 44 21 49 43 29 50 22 38 
Passed
Test Case 2
20
28 34 34 14 41 9 16 36 41 40 5 31 7 33 40 19 29 13 15 1
23 46 38 7 24 34 38 27 36 4 40 26 5 1 25 18 34 28 25 13
28 21 27 21 28 12 8 47 45 32 26 12 20 34 21 23 30 41 34 2
20 31 38 50 13 48 45 2 27 25 7 35 44 38 42 26 34 45 23 31
3 13 35 7 7 24 10 16 36 15 23 26 42 11 25 14 19 7 26 20
7 24 40 49 20 48 30 29 29 8 19 13 32 24 25 32 35 23 45 47
42 24 45 48 8 9 8 49 4 13 14 26 36 47 48 1 8 38 5 36
42 26 6 32 42 24 11 4 46 33 36 13 17 26 18 6 44 12 49 23
46 28 35 5 3 15 28 35 15 40 47 33 25 2 9 39 31 23 8 6
40 18 45 31 8 41 18 5 37 27 19 49 43 39 31 8 16 1 4 22
12 48 48 6 15 39 41 47 20 43 48 24 42 7 29 16 34 44 37 7
48 24 11 11 41 40 30 5 44 43 5 2 36 10 1 1 18 38 16 22
50 12 28 10 21 26 1 46 4 26 15 36 37 17 13 38 23 37 17 36
5 3 14 34 41 4 50 45 30 33 7 18 34 39 31 33 30 2 2 7
46 10 36 15 32 46 35 32 9 6 37 48 36 3 21 5 3 37 31 6
48 22 36 7 15 41 12 21 39 33 46 10 27 46 16 10 28 18 33 1
40 25 29 22 27 42 17 35 49 22 48 41 20 5 19 24 37 6 8 12
44 47 33 32 43 22 7 41 8 41 47 24 14 37 46 38 9 25 2 12
28 38 47 24 44 39 16 41 37 22 40 44 14 37 1 48 35 17 8 28
10 22 1 19 5 35 2 43 42 43 24 42 34 21 1 6 45 16 9 7
28 23 28 20 3 7 42 42 46 40 12 48 50 5 46 48 40 44 28 10 22 1 19 5 35 2 43 42 43 24 42 34 21 1 6 45 16 9 7 28 12 12 1 6 7 36 22 7 22 6 23 36 47 20 31 2 13 1 15 13 29 19 40 33 7 31 5 40 41 36 16 9 41 14 34 34 46 21 31 13 24 24 26 28 18 48 24 12 3 10 22 25 47 38 47 24 44 39 16 41 37 22 40 44 14 37 1 48 35 17 8 2 8 33 31 2 17 16 37 4 8 49 5 45 26 23 34 25 28 34 18 25 1 5 26 40 4 36 27 38 34 24 7 38 27 38 35 40 45 6 35 45 48 11 28 14 36 36 29 33 32 43 22 7 41 8 41 47 24 14 37 46 38 9 25 6 18 37 2 37 38 44 1 23 12 38 23 7 45 41 30 23 21 34 20 12 26 32 45 47 8 12 28 21 50 7 49 48 32 5 31 6 11 10 34 15 7 22 27 42 17 35 49 22 48 41 20 5 19 24 37 28 3 30 23 18 34 16 31 44 8 35 19 34 26 42 38 44 35 7 25 27 2 45 48 13 7 20 8 42 3 8 15 41 21 41 32 15 41 12 21 39 33 46 10 27 46 16 10 5 33 38 1 16 8 39 6 1 32 14 25 11 42 26 23 15 36 16 10 24 48 9 24 15 41 39 40 26 4 46 35 32 9 6 37 48 36 3 21 31 13 1 29 31 9 18 48 25 24 32 13 19 8 29 29 30 8 11 28 18 41 30 1 50 45 30 33 7 18 34 39 17 10 7 39 2 26 47 36 26 14 13 4 49 4 35 5 47 5 46 4 26 15 36 37 36 42 43 25 17 13 36 33 46 15 37 20 44 43 5 2 24 49 33 47 40 27 43 48 19
28 23 28 20 3 7 42 42 46 40 12 48 50 5 46 48 40 44 28 10 22 1 19 5 35 2 43 42 43 24 42 34 21 1 6 45 16 9 7 28 12 12 1 6 7 36 22 7 22 6 23 36 47 20 31 2 13 1 15 13 29 19 40 33 7 31 5 40 41 36 16 9 41 14 34 34 46 21 31 13 24 24 26 28 18 48 24 12 3 10 22 25 47 38 47 24 44 39 16 41 37 22 40 44 14 37 1 48 35 17 8 2 8 33 31 2 17 16 37 4 8 49 5 45 26 23 34 25 28 34 18 25 1 5 26 40 4 36 27 38 34 24 7 38 27 38 35 40 45 6 35 45 48 11 28 14 36 36 29 33 32 43 22 7 41 8 41 47 24 14 37 46 38 9 25 6 18 37 2 37 38 44 1 23 12 38 23 7 45 41 30 23 21 34 20 12 26 32 45 47 8 12 28 21 50 7 49 48 32 5 31 6 11 10 34 15 7 22 27 42 17 35 49 22 48 41 20 5 19 24 37 28 3 30 23 18 34 16 31 44 8 35 19 34 26 42 38 44 35 7 25 27 2 45 48 13 7 20 8 42 3 8 15 41 21 41 32 15 41 12 21 39 33 46 10 27 46 16 10 5 33 38 1 16 8 39 6 1 32 14 25 11 42 26 23 15 36 16 10 24 48 9 24 15 41 39 40 26 4 46 35 32 9 6 37 48 36 3 21 31 13 1 29 31 9 18 48 25 24 32 13 19 8 29 29 30 8 11 28 18 41 30 1 50 45 30 33 7 18 34 39 17 10 7 39 2 26 47 36 26 14 13 4 49 4 35 5 47 5 46 4 26 15 36 37 36 42 43 25 17 13 36 33 46 15 37 20 44 43 5 2 24 49 33 47 40 27 43 48 19 
Passed
Test Case 3
4
50 36 24 28
18 14 19 12
31 40 42 45
4 15 38 45
50 18 31 4 15 38 45 45 12 28 24 36 14 40 42 19
50 18 31 4 15 38 45 45 12 28 24 36 14 40 42 19 
Passed

Due Date Exceeded.
3 out of 3 tests passed.
You scored 100.0/100.
PROGRAM:
a=int(input())
mat=[]
for i in range(0,a):
  l=list(map(int,input().split()))
  mat.append(l)
m=a
n=a
k=0
l=0
count=0
total=a*a
while(k<m and l<n):
  if(count==total):
    break
  for i in range(k,m):
    print(mat[i][l],end=" ")
    count += 1
  l += 1
 
  if(count==total):
    break
  for i in range(l,n):
    print(mat[m-1][i],end=" ")
    count += 1
  m-=1
 
  if(count==total):
    break
  if(k<m):
    for i in range(m-1,k-1,-1):
      print(mat[i][n-1],end=" ")
      count += 1
  n-= 1
 
  if(count==total):
    break
  if(l<n):
    for i in range(n-1,l-1,-1):
      print(mat[k][i],end=" ")
      count +=1
  k += 1
                       OR
def counterClockspiralPrint(m, n, arr) :
    k = 0; l = 0
    
    # k - starting row index
    # m - ending row index
    # l - starting column index
    # n - ending column index
    # i - iterator

    # initialize the count
    cnt = 0

    # total number of
    # elements in matrix
    total = m * n

    while (k < m and l < n) :
        if (cnt == total) :
            break

        # Print the first column
        # from the remaining columns
        for i in range(k, m) :
            print(arr[i][l], end = " ")
            cnt += 1
        
        l += 1

        if (cnt == total) :
            break

        # Print the last row from
        # the remaining rows
        for i in range (l, n) :
            print( arr[m - 1][i], end = " ")
            cnt += 1
        
        m -= 1
        
        if (cnt == total) :
            break

        # Print the last column 
        # from the remaining columns
        if (k < m) :
            for i in range(m - 1, k - 1, -1) :
                print(arr[i][n - 1], end = " ")
                cnt += 1
            n -= 1

        if (cnt == total) :
            break

        # Print the first row
        # from the remaining rows
        if (l < n) :
            for i in range(n - 1, l - 1, -1) :
                print( arr[k][i], end = " ")
                cnt += 1
                
            k += 1
            

# Driver Code
num = int(input())
R = num
C = num

arr = []
for i in range(1,num+1):   
    l = list(map(int, input ().split ()))
    arr.append(l)
        
counterClockspiralPrint(R, C, arr)

Programming Assignment-2: Maximum Numeric


Given an alphanumeric string S, extract maximum numeric value from that string. All the alphabets are in lower case. Take the maximum consecutive digits as a single number.

Input Format:
The first line contains the string S.

Output Format:
Print the maximum value

Example:
Input:
23dsa43dsa98

Output:
98

Explanation:
There are three integer values present in the string, 23, 43 and 98. Among these, 98 is the maximum.
Private Test cases used for evaluation Input Expected Output Actual Output Status
Test Case 1
amit123aman786
786
786
Passed
Test Case 2
ghjldsagjulsda1234hdsjkalgjk8765dsgayhuf3214bjdksa234bhfjksahj9878dsahjk567
9878
9878
Passed
Test Case 3
1g2g3g4g5g6g7g8
8
8
Passed

Due Date Exceeded.
3 out of 3 tests passed.
You scored 100.0/100.
PROGRAM:
import re
ip=input()
l=((re.findall('\d+', ip)))
l=list(map(int,l))
print(max(l),end='')
             OR
import re
 
def extractMax(input):
 
     # get a list of all numbers separated by 
     # lower case characters 
     # \d+ is a regular expression which means
     # one or more digit
     # output will be like ['100','564','365']
     numbers = re.findall('\d+',input)
 
     # now we need to convert each number into integer
     # int(string) converts string into integer
     # we will map int() function onto all elements 
     # of numbers list
     numbers = map(int,numbers)
 
     print(max(numbers))

S = input()
extractMax(S)

Programming Assignment-3: Email ID

Assuming that we have some email addresses in the "username@companyname.com" format, please write program to print the company name of a given email address. Both user names and company names are composed of letters only.

Input Format:
The first line of the input contains an email address.

Output Format:
Print the company name in single line.

Example;

Input:
john@google.com

Output:
google
Private Test cases used for evaluation Input Expected Output Actual Output Status
Test Case 1
amit@dsi.com
dsi
dsi
Passed
Test Case 2
sumit@amazon.com
amazon
amazon
Passed
Test Case 3
ajay@manga.com
manga
manga
Passed

Due Date Exceeded.
3 out of 3 tests passed.
You scored 100.0/100.
PROGRAM:
ip=input()
x=ip.index("@")
print(ip[x+1:len(ip)-4],end='')
           OR
import re
emailAddress = input()
pat2 = "(\w+)@(\w+)\.(com)"
r2 = re.match(pat2,emailAddress)
print(r2.group(2))
 
 
 
 
 
 
 
 
 
 
 

  







No comments:

Post a Comment