Home

Learn Programming & Prepare for NPTEL Exams... Swayam Solver is your one-stop destination for NPTEL exam preparation.

NPTEL The Joy of Computing using Python July - 2024 | Swayam

 

NPTEL » The Joy of Computing using Python


  Please scroll down for latest Programs 👇 


Programming Assignment 1

Due on 2024-08-08, 23:59 IST
Create a Python program that calculates the absolute value of a given number.
The program should prompt the user to input a number, then compute and print the absolute value of that number.

Input Format-
The input consists of single number.

Output Format-

The output consists of absolute value of the input.

Example-
Input:
-6
Output:
6


Select the Language for this assignment. 
1
~~~THERE IS SOME INVISIBLE CODE HERE~~~
2
# write your code here
3
#print("Input a number ")
4
n = int(input())
5
if n < 0 :
6
  print(-n , end="")
7
else:
8
  print(n , end="")
9
0
~~~THERE IS SOME INVISIBLE CODE HERE~~~
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
1
1
1
Passed
Test Case 2
-1
1
1
Passed
Test Case 3
-6
6
6
Passed




Private Test cases used for EvaluationStatus
Test Case 1
Passed
Test Case 2
Passed
Test Case 3
Passed



Programming Assignment 2

Due on 2024-08-08, 23:59 IST
Create a Python program to determine the nth element of an arithmetic sequence where the first term a is 7 and the common difference  is 11. The program should prompt the user to input the value of n, then compute and print the nth element of the sequence.

Input Format:
The input consists of a single integer n.

Output Format:

The output consists of the nth element of the arithmetic sequence.

Example:
Input:
3
Output:
29

Select the Language for this assignment. 
1
a = 7
2
d = 11
3
# Write your code here
4
n = int(input())
5
print( a + (n-1)*d , end="")
0
~~~THERE IS SOME INVISIBLE CODE HERE~~~
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
3
29
29
Passed
Test Case 2
1
7
7
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed
Test Case 2
Passed
Test Case 3
Passed
Test Case 4
Passed



Programming Assignment 3

Due on 2024-08-08, 23:59 IST

Question:

Create a Python program to compute the sum of the first N natural numbers {1,2,3...N}. The program should prompt the user to input the value of N, then compute and print the sum of the first natural numbers.

Input Format:
The input consists of a single integer .

Output Format:
The output consists of the sum of the first  natural numbers.

Example:
Input-
5
Output-
15

Select the Language for this assignment. 
1
~~~THERE IS SOME INVISIBLE CODE HERE~~~
2
# Write your code here
3
n = int(input())
4
print( n*(n+1)//2 , end="")
0
~~~THERE IS SOME INVISIBLE CODE HERE~~~
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
5
15
15
Passed
Test Case 2
4
10
10
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed
Test Case 2
Passed
Test Case 3
Passed






Week 3: Programming Assignment 1

Due on 2024-08-15, 23:59 IST
Create a Python program that finds the second largest number in a list of positive integers(includes zero). The program should prompt the user to input a list of numbers, then compute and print the second largest number in that list.

Input Format:
The input consists of a single list of numbers, separated by spaces.
Hint: Use .split() function to convert input to list.

Output Format:
The output consists of the second largest number in the input list.

Example:

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

Output:
6

Your last recorded submission was on 2024-08-08, 23:35 IST
Select the Language for this assignment. 
1
L = input().split(' ')
2
L = [int(num) for num in L]
3
max1 = L[0]
4
for x in L:
5
  if x > max1:
6
    max1 = x
7
for x in L:
8
  if x != max1:
9
    max2 = x
10
for x in L:
11
  if x > max2 and x != max1:
12
    max2 = x
13
print(max2, end='')
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
3 1 4 1 5 9 2 6 5 3 5
6
6
Passed
Test Case 2
1 1 0
0
0
Passed
Test Case 3
11 12 10 33
12
12
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed
Test Case 2
Passed
Test Case 3
Passed



Week 3: Programming Assignment 2

Due on 2024-08-15, 23:59 IST
Create a Python program that removes all duplicate positive integer numbers(includes zero) from a list and prints the unique numbers in the order they first appeared.
The program should prompt the user to input a list of numbers, then process the list to remove duplicates and print the resulting list of unique numbers.

Input Format:
The input consists of a single list of numbers, separated by spaces.

Output Format:
The output consists of the unique numbers, separated by spaces, from the input list, in the order they first appeared.

Example:
Input:
3 1 4 1 5 9 2 6 5 3 5
Output:
3 1 4 5 9 2 6

Your last recorded submission was on 2024-08-09, 12:37 IST
Select the Language for this assignment. 
1
L = input().split(' ')
2
for x in L:
3
  if x in L[L.index(x)+1:]:
4
    del L[L.index(x, L.index(x)+1)]
5
print(' '.join( L), end='')
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
3 1 4 1 5 9 2 6 5 3 5
3 1 4 5 9 2 6
3 1 4 5 9 2 6
Passed
Test Case 2
2 3 4 2 5 6 1
2 3 4 5 6 1
2 3 4 5 6 1
Passed
Test Case 3
2 3 45 55 55 2
2 3 45 55
2 3 45 55
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed
Test Case 2
Passed
Test Case 3
Passed



Week 3: Programming Assignment 3

Due on 2024-08-15, 23:59 IST

Create a Python program that takes a list of integers, reverses the list, adds the values at odd indices from both the original and reversed lists, and creates a new list with the result. The new list should be printed in the end.

Input Format:
The input consists of a single list of integers, separated by spaces.

Output Format:
The output consists of the new list of values, separated by spaces, obtained by adding values at odd indices from both the original and reversed lists.


Example:
Input:

1 2 3 4 5

Output:
1 6 3 6 5

Your last recorded submission was on 2024-08-09, 13:47 IST
Select the Language for this assignment. 
1
L = input().split(' ')
2
L = [int(num) for num in L]
3
l = []
4
for i in range(len(L)):
5
  if i % 2:
6
    l += [L[i] + L[-(i+1)]]
7
  else:
8
    l += [L[i]]
9
print(' '.join(map(str,l)), end='')
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
1 2 3 4 5
1 6 3 6 5
1 6 3 6 5
Passed
Test Case 2
2 3 37 43 21
2 46 37 46 21
2 46 37 46 21
Passed
Test Case 3
1 0
1 1
1 1
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed
Test Case 2
Passed
Test Case 3
Passed




Week 4: Programming Assignment 1

Due on 2024-08-22, 23:59 IST
Create a Python program that identifies the presence of a "saddle point" in a given matrix. A saddle point is defined as an element in the matrix that is the smallest in its row and the largest in its column. The matrix is represented as a nested list, where each nested list corresponds to a row of the matrix. The program should determine if at least one saddle point exists in the matrix. If a saddle point is found, the program/function should print 1; otherwise, it should print 0.

Input Format:
The first input is an integer r , the number of rows in the matrix.
The second input is an integer c, the number of columns in the matrix.
The next r lines each contain c integers, representing the elements of each row of the matrix.

Output Format:
The output is 1 if a saddle point exists, otherwise 0.


Example:

Input:

3
3
2 0 3
2 1 4
4 2 6

Output:
1

Reason:
Element 2 in third row and second column is minimum in its row and maximum in its column.
So, it is a saddle point.

Your last recorded submission was on 2024-08-20, 20:11 IST
Select the Language for this assignment. 
1
r = int(input())
2
c = int(input())
3
A = [ ]
4
for i in range(r):
5
  row = [ ]
6
  for x in input().split(' '):
7
    row.append(int(x))
8
  A.append(row)
9
flag = 0
10
for i in range(r):
11
  if flag:
12
    break
13
  for j in range(c):
14
    element = A[i][j]
15
    if element == min(A[i]):
16
      if A[i].count(element) > 1:
17
        continue
18
      col = []
19
      for m in range(r):
20
        col += [A[m][j]]
21
      if element == max(col):
22
        flag = 1
23
        break
24
print(flag, end='')
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
3
3
2 2 3
2 1 4
4 0 6
0
0
Passed
Test Case 2
3
3
2 0 3
2 1 4
4 2 6
1
1
Passed
Test Case 3
4
4
7 3 5 8
4 2 9 1
2 2 10 11
14 1 7 3
1
1
Passed



Week 4: Programming Assignment 2

Due on 2024-08-22, 23:59 IST

Create a Python program that multiplies the transpose of a given matrix by a scalar. The program should prompt the user to input the dimensions of the matrix, the elements of the matrix, and the scalar value. The program should then compute the transpose of the matrix, multiply it by the scalar, and print the resulting matrix.

Input:
The first input is an integer 𝑟 , the number of rows in the matrix.
The second input is an integer 𝑐 , the number of columns in the matrix.
The next 𝑟 lines each contain 𝑐 integers, representing the elements of the matrix.
The final input is an integer 𝑠, representing the scalar value.

Output Format:
The output consists of 𝑐 lines, each containing 𝑟 integers, representing the elements of the resulting matrix after multiplying the transpose of the original matrix by the scalar.


Example:

Input:

2
3
1 2 3
4 5 6
2

Output:
2 8
4 10
6 12

Your last recorded submission was on 2024-08-11, 19:19 IST
Select the Language for this assignment. 
1
r = int(input())
2
c = int(input())
3
A = [ ]
4
for i in range(r):
5
  row = [ ]
6
  for x in input().split(' '):
7
    row.append(int(x))
8
  A.append(row)
9
s = int(input())
10
T = [ ]
11
for j in range(c):
12
  row = [ ]
13
  for i in range(r):
14
    row.append(A[i][j])
15
  T.append(row)
16
for i in range(c):
17
  for j in range(r):
18
    if j == r-1:
19
      print(T[i][j]*s, end="")
20
    else :
21
      print(T[i][j]*s, end=" ")
22
  if (i,j)!=(c-1,r-1):
23
    print()
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
2
3
1 2 3
4 5 6
2
2 8\n
4 10\n
6 12
2 8\n
4 10\n
6 12
Passed
Test Case 2
3
2
1 2
3 4
5 6
3
3 9 15\n
6 12 18
3 9 15\n
6 12 18
Passed
Test Case 3
2
2
-1 0
2 -3
4
-4 8\n
0 -12
-4 8\n
0 -12
Passed



Week 4: Programming Assignment 3

Due on 2024-08-22, 23:59 IST
Create a Python program that checks whether a given square matrix is skew-symmetric. A matrix is skew-symmetric if its transpose is equal to the negative of the matrix itself, i.e =  .The program should prompt the user to input the dimensions of the matrix and then input the matrix elements. The program should then determine whether the matrix is skew-symmetric and print 1 if it is, otherwise print 0.

Input Format:
The first input is an integer r , the number of rows and columns in the matrix.
The next r lines each contain r integers, representing the elements of each row of the matrix.

Output Format:
The output is 1 if a matrix is skew-symmetric, otherwise 0.


Example:

Input:

3
0 2 -1
-2 0 -4
1 4 0

Output:
1

Your last recorded submission was on 2024-08-11, 19:22 IST
Select the Language for this assignment. 
1
r = int(input())
2
A = [ ]
3
for i in range(r):
4
  row = [ ]
5
  for x in input().split(' '):
6
    row.append(int(x))
7
  A.append(row)
8
T = [ ]
9
for j in range(r):
10
  row = [ ]
11
  for i in range(r):
12
    row.append(A[i][j])
13
  T.append(row)
14
flag = 0
15
for i in range(r):
16
  for j in range(r):
17
    if A[i][j] == -1 * T[i][j]:
18
      continue
19
    else :
20
      print(0, end='')
21
      flag = 1
22
      break
23
  if flag :
24
    break
25
else:
26
  print(1, end='')
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
3
0 2 -1
-2 0 -4
1 4 0
1
1
Passed
Test Case 2
3
0 2 -1
-2 0 4
1 4 0
0
0
Passed
Test Case 3
4
0 2 -3 4
-2 0 5 -6
3 -5 0 7
-4 6 -7 0
1
1
Passed




Week 5: Programming Assignment 1

Due on 2024-08-29, 23:59 IST

Create a Python program that performs a binary search on a sorted list of integers using only loops. The program should prompt the user to input a sorted list of integers and a target number to search for. The program should then search for the target number in the list using the binary search algorithm and print the index of the target if found. If the target is not found, the program should print -1.

Input Format:

  • The first line of input consists of a space-separated sorted list of integers.
  • The second line of input consists of a single integer, representing the target number.

Output Format:

  • The output consists of the index of the target number in the list if found. If the target number is not found, the output should be -1.

Example:
Input:
10 20 30 40 50
30

Output:
2

Your last recorded submission was on 2024-08-16, 20:32 IST
Select the Language for this assignment. 
1
L = input().split(' ')
2
L = [int(num) for num in L]
3
x = int(input())
4
5
first_pos = 0
6
last_pos = len(L)-1
7
flag=0
8
count = 0
9
while(first_pos<=last_pos and flag==0):
10
  count+=1
11
  mid = (first_pos+last_pos)//2
12
  if (x==L[mid]):
13
    flag = 1
14
    print(mid,end ='')
15
    break
16
  else:
17
    if (x < L[mid]):
18
      last_pos = mid-1
19
    else:
20
      first_pos = mid+1
21
else:
22
  print('-1',end ='')
23
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
10 20 30 40 50
30
2
2
Passed
Test Case 2
1 2 3 4 5 6 7 8 9
5
4
4
Passed
Test Case 3
2 3 5 6 8 9 10 12 13
14
-1
-1
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed
Test Case 2
Passed
Test Case 3
Passed



Week 5: Programming Assignment 2

Due on 2024-08-29, 23:59 IST
Create a Python program that merges two sorted lists into one sorted list. The program should prompt the user to input two sorted lists of integers. The program should then merge these two lists into one sorted list and print the result.

Input Format:
The first line of input consists of a space-separated sorted list of integers.
The second line of input consists of another space-separated sorted list of integers.

Output Format:
- The output consists of a single sorted list, which is the result of merging the two input lists.

Example:

Input:
1 3 5 7
2 4 6 8


Output:
1 2 3 4 5 6 7 8



Your last recorded submission was on 2024-08-17, 16:39 IST
Select the Language for this assignment. 
1
L1 = input().split(' ')
2
L1 = [int(num) for num in L1]
3
L2 = input().split(' ')
4
L2 = [int(num) for num in L2]
5
L = []
6
c1,c2 = 0,0
7
while(1):
8
  if c1 < len(L1) and L1[c1] <= L2[c2]:
9
    L += [L1[c1]]
10
    c1+=1
11
    if c1 == len(L1):
12
      L += L2[c2:]
13
      break
14
  elif c2 < len(L2) and L2[c2] <= L1[c1]:
15
    L += [L2[c2]]
16
    c2+=1
17
    if c2 == len(L2):
18
      L += L1[c1:]
19
      break
20
print(' '.join(map(str,L)), end='')
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
10 20 30 40 50
5 70 90 100
5 10 20 30 40 50 70 90 100
5 10 20 30 40 50 70 90 100
Passed
Test Case 2
1 3 7 9
2 4 6 8
1 2 3 4 6 7 8 9
1 2 3 4 6 7 8 9
Passed
Test Case 3
1 3 5 6 8 9 10 12 17
1 7 20 100
1 1 3 5 6 7 8 9 10 12 17 20 100
1 1 3 5 6 7 8 9 10 12 17 20 100
Passed




Private Test cases used for EvaluationStatus
Test Case 1
Passed
Test Case 2
Passed
Test Case 3
Passed



Week 5: Programming Assignment 3

Due on 2024-08-29, 23:59 IST
Create a Python program that finds the k-th largest and k-th smallest elements in a list of integers. The program should prompt the user to input a list of integers and a value `k`. The program should then find and print:

  • 1 if the k-th largest and k-th smallest elements are the same and are at the middle of the sorted list.
  •  -1 if the k-th largest and k-th smallest elements are the same but are not in the middle of the sorted list.
  • 0 if the k-th largest and k-th smallest elements are different.
Input Format:
  • The first line of input consists of a space-separated list of integers.
  • The second line of input consists of a single integer k.

Output Format:
The output consists of a single integer 1, -1, or 0 based on the conditions specified.

Example:

Input:
3 8 7 5 9 1
2

Output:
0

Your last recorded submission was on 2024-08-17, 16:29 IST
Select the Language for this assignment. 
1
L = input().split(' ')
2
L = [int(num) for num in L]
3
k = int(input())
4
L.sort()
5
if L[k-1] == L[-k]:
6
  if k == len(L)//2+1:
7
    print('1',end = '')
8
  else:
9
    print('-1',end = '')
10
else:
11
  print('0',end = '')
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
3 8 7 5 9 1
2
0
0
Passed
Test Case 2
2 1 1 3
2
0
0
Passed
Test Case 3
700
1
1
1
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed
Test Case 2
Passed
Test Case 3
Passed



Week 6: Programming Assignment 1

Due on 2024-09-05, 23:59 IST

Question:
Write a Python program that takes two positive integers a and b as input and returns their product using a recursive function. The function should only use the + and - operators to calculate the product.

Input Format:
The first line of input consists of two space-separated positive integers, a and b.

Output Format:
The output consists of a single integer representing the product of a and b.

Example:

Input:
3 4

Output:
12

Your last recorded submission was on 2024-08-25, 07:46 IST
Select the Language for this assignment. 
1
L = input().split(' ')
2
a = int(L[0])
3
b = int(L[1])
4
def recursive_product(a,b):
5
  if b == 0:
6
    return 0
7
  if b == 1:
8
    return a
9
  else:
10
    return a + recursive_product(a,b-1)
11
print(recursive_product(a,b), end='')
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
1 1
1
1
Passed
Test Case 2
3 4
12
12
Passed
Test Case 3
999 1
999
999
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed
Test Case 2
Passed
Test Case 3
Passed
Test Case 4
Passed



Week 6: Programming Assignment 2

Due on 2024-09-05, 23:59 IST

Question:
Write a Python program that takes a positive integer x as input and returns the logarithm of x to the base 2 using a recursive function. The logarithm of x to the base 2, denoted by log₂(x), is the number of times 2 has to be multiplied by itself to get x. Assume that x is a power of 2.

Input Format:
The input consists of a single positive integer x which is a power of 2.

Output Format:
The output consists of a single integer representing log₂(x).

Example:

Input:
8

Output:
3

Your last recorded submission was on 2024-08-25, 07:57 IST
Select the Language for this assignment. 
1
a = int(input())
2
def log2(a):
3
  if a == 1:
4
    return 0
5
  else:
6
    return 1 + log2(a/2)
7
print(log2(a), end='')
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
2
1
1
Passed
Test Case 2
4
2
2
Passed
Test Case 3
16
4
4
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed
Test Case 2
Passed
Test Case 3
Passed



Week 6: Programming Assignment 3

Due on 2024-09-05, 23:59 IST

Question
Write a Python program that includes a recursive function named non_decreasing which takes a non-empty list L of integers as input. The function should return True if the elements in the list are sorted in non-decreasing order from left to right, and False otherwise.

Input Format:
The input consists of a single line containing space-separated integers that form the list L.

Output Format:
The output consists of a single boolean value (True or False) indicating whether the list is sorted in non-decreasing order.

Example:

Input:
1 2 2 3 4

Output:
True

Your last recorded submission was on 2024-08-25, 08:51 IST
Select the Language for this assignment. 
1
L = input().split(' ')
2
L = [int(num) for num in L]
3
def non_decreasing(L):
4
  if len(L) == 1:
5
    return True
6
  else:
7
    return L[1]-L[0] >=0 and non_decreasing(L[1:])
8
print(non_decreasing(L),end='')
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
1 2 2 3 4
True
True
Passed
Test Case 2
3 2 1
False
False
Passed
Test Case 3
11 22 45 89 100 483
True
True
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed
Test Case 2
Passed
Test Case 3
Passed




Week 7: Programming Assignment 1

Due on 2024-09-12, 23:59 IST

Question
You are given a board game scenario with ladders and snakes. A player starts at a given position on the board, and you are provided with the result of a die roll. You need to determine whether the player lands on a ladder, a snake, or a normal block after moving.

Write a Python function named move_player that takes four inputs:

  • A list ladders containing the indices of blocks with ladders.
  • A list snakes containing the indices of blocks with snakes.
  • An integer current_position representing the player's current position on the board.
  • An integer die_roll representing the result of a die roll.

The function should return:

  • 1 if the player lands on a block with a ladder,
  • -1 if the player lands on a block with a snake,
  • 0 if the player lands on a block with neither.
Take necessary inputs, pass the inputs to the function, and print the return value of the function.

Input Format
The input consists of four lines:

  1. The first line contains space-separated integers representing the ladder indices.
  2. The second line contains space-separated integers representing the snake indices.
  3. The third line contains a single integer representing the current position of the player.
  4. The fourth line contains a single integer representing the die roll result.

Output Format
The output consists of a single integer (1-1, or 0) as per the conditions mentioned above.

Your last recorded submission was on 2024-08-30, 15:25 IST
Select the Language for this assignment. 
1
ladders = input().split(' ')
2
ladders = [int(num) for num in ladders]
3
snakes = input().split(' ')
4
snakes = [int(num) for num in snakes]
5
current_position = int(input())
6
die_roll = int(input())
7
def move_player(ladders, snakes, current_position, die_roll):
8
  new_position = current_position + die_roll
9
  if new_position in ladders:
10
    return 1
11
  elif new_position in snakes:
12
    return -1
13
  else:
14
    return 0
15
print(move_player(ladders, snakes, current_position, die_roll) , end='')
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
3 8 12
6 14 18
5
3
1
1
Passed
Test Case 2
4 8 12 11 67 43
2 15 18 19 56 9
10
6
0
0
Passed
Test Case 3
2 6 14 19 26 67 5
7 12 17 98 3 76 4 18
3
4
-1
-1
Passed




Week 7: Programming Assignment 2

Due on 2024-09-12, 23:59 IST

Question

Write a Python program that includes a recursive function named is_palindrome which takes a non-empty string s as input. The function should return 1 if the string is a palindrome (reads the same backward as forward), and 0 otherwise.

Take necessary inputs, pass the inputs to the function, and print the return value of the function.

Input Format:

The input consists of a single line containing the string s.

Output Format:

The output consists of a single integer value (1 or 0) indicating whether the string is a palindrome.

Example:

Input:
racecar

Output
1

Your last recorded submission was on 2024-08-30, 16:00 IST
Select the Language for this assignment. 
1
s = input()
2
def is_palindrome(s):
3
  if len(s) == 0:
4
    return 1
5
  elif len(s) == 1:
6
    return 1
7
  else:
8
    return s[0] == s[-1] and is_palindrome(s[1:-1])
9
print(int(is_palindrome(s)) , end='')
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
racecar
1
1
Passed
Test Case 2
level
1
1
Passed
Test Case 3
dinosaur
0
0
Passed




Week 7: Programming Assignment 3

Due on 2024-09-12, 23:59 IST

Question

Write a Python program that takes a matrix of size r x c as input, where r is the number of rows and c is the number of columns. The program should check if the matrix is binary (i.e., all elements are either 0 or 1) and if it is symmetric (i.e., the matrix is equal to its transpose).

The program should output:

  • 11 if the matrix is both binary and symmetric,
  • 10 if the matrix is binary but not symmetric,
  • 01 if the matrix is not binary but symmetric,
  • 00 if the matrix is neither binary nor symmetric.

Input Format:

  • The first line contains an integer r representing the number of rows.
  • The second line contains an integer c representing the number of columns.
  • The next r lines each contain c space-separated integers representing the elements of the matrix.

Output Format:

  • The output consists of a single string (either 111001, or 00) as per the conditions mentioned above.

Example:

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

Output:
11

Your last recorded submission was on 2024-08-30, 16:24 IST
Select the Language for this assignment. 
1
r = int(input())
2
c = int(input())
3
A = [ ]
4
for i in range(r):
5
  row = [ ]
6
  for x in input().split(' '):
7
    row.append(int(x))
8
  A.append(row)
9
T = [ ]
10
for j in range(c):
11
  row = [ ]
12
  for i in range(r):
13
    row.append(A[i][j])
14
  T.append(row)
15
b_flag = True
16
for i in range(c):
17
  for j in range(r):
18
    if A[i][j] != 0 and A[i][j] != 1:
19
      b_flag = False
20
      break
21
if b_flag == True:
22
  print('1' , end='')
23
else:
24
  print('0' , end='')
25
if T == A:
26
  print('1' , end='')
27
else:
28
  print('0' , end='')
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
3
3
1 0 1
0 1 0
1 0 1
11
11
Passed
Test Case 2
3
3
1 0 2
0 1 0
2 0 1
01
01
Passed
Test Case 3
3
3
1 0 1
1 1 0
1 0 1
10
10
Passed
Test Case 4
3
3
1 0 2
3 1 0
2 0 1
00
00
Passed





Private Test cases used for EvaluationStatus
Test Case 1
Passed
Test Case 2
Passed
Test Case 3
Passed
Test Case 4
Passed
Test Case 5
Passed
Test Case 6
Passed





Week 8: Programming Assignment 1

Due on 2024-09-19, 23:59 IST

Write a function that takes an integer n followed by n lines of space-separated integers, where each line represents a tuple. The function should return the sum of the first elements of all tuples.

Input Format:

  • The first line contains a single integer n, which represents the number of tuples.
  • The next n lines each contain two space-separated integers representing the values of the tuple.

Output Format:

  • A single integer representing the sum of the first elements of all tuples.

Example:

Input:

3
3 4
1 2
5 6

Output:
9


Your last recorded submission was on 2024-09-06, 15:37 IST
Select the Language for this assignment. 
1
def fun():
2
  sum = 0
3
  n = int(input())
4
  for i in range(n):
5
    L = input().split(' ')
6
    L = [int(num) for num in L]
7
    sum += L[0]
8
  return(sum)
9
print(fun(), end='')
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
2
1 10
2 20
3
3
Passed
Test Case 2
4
5 12
7 8
1 5
3 9
16
16
Passed
Test Case 3
1
9 10
9
9
Passed




Week 8: Programming Assignment 2

Due on 2024-09-19, 23:59 IST

Question:

Write a function that checks if two given strings are anagrams of each other considering only alphabetic characters and ignoring case. Additionally, the function should handle cases where the strings may contain spaces or punctuation, and should return the result as 1 or 0.

Input Format:

  • The first line contains a string str1 which may include alphabetic characters, spaces, and punctuation.
  • The second line contains a string str2 which may also include alphabetic characters, spaces, and punctuation.

Output Format:

  • Print if the two strings are anagrams of each other, considering only alphabetic characters and ignoring case, otherwise print 0.

Example:

Input:

Astronomer
Moon starer

Output:
1


Your last recorded submission was on 2024-09-06, 17:19 IST
Select the Language for this assignment. 
1
def are_anagrams(str1, str2):
2
  letters1 = ''
3
  letters2 = ''
4
  for i in str1:
5
    if i.isalpha():
6
      letters1 +=i.lower()
7
  for i in str2:
8
    if i.isalpha():
9
      letters2 +=i.lower()
10
  return(int(sorted(letters1) == sorted(letters2)))
11
str1 = input()
12
str2 = input()
13
print(are_anagrams(str1, str2), end='')
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
The Morse Code
Here come dots
1
1
Passed
Test Case 2
A gentleman
Elegant man
1
1
Passed
Test Case 3
Claremont
Montreal
0
0
Passed



Week 8: Programming Assignment 3

Due on 2024-09-19, 23:59 IST

Question:

Write a function that takes a list of integers and an integer k. The function should multiply each integer in the list by k and then return the maximum value from the resulting list.

Input Format:

  • The first line contains space-separated integers representing the list of numbers.
  • The second line contains a single integer k, the multiplier.

Output Format:

  • Print a single integer representing the maximum value after multiplying each number by k.

Example:

Input:
1 5 3 9
2

Output:
18





Your last recorded submission was on 2024-09-06, 15:59 IST
Select the Language for this assignment. 
1
def fun(L,k):
2
  for i in range(len(L)):
3
    L[i] *= k
4
  return(max(L))
5
L = input().split(' ')
6
L = [int(num) for num in L]
7
k = int(input())
8
print(fun(L,k), end='')
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
1 5 3 9
2
18
18
Passed
Test Case 2
4 7 2 8
3
24
24
Passed
Test Case 3
8 15 4 10
6
90
90
Passed




Week 9: Programming Assignment 1

Due on 2024-09-26, 23:59 IST

Write a function that takes a string and counts the number of vowels in it. The function should return the total number of vowels.

Input Format:

The input consists of a single string. The string can contain both uppercase and lowercase letters, as well as spaces and punctuation marks.

Output Format:

A single integer representing the total number of vowels in the string.

Example:

Input:

Hello, World!

Output:

3






Your last recorded submission was on 2024-09-14, 08:37 IST
Select the Language for this assignment. 
1
def vowels(str):
2
  count = 0
3
  v = ['a','e','i','o','u','A','E','I','O','U']
4
  for l in str:
5
    if l in v:
6
      count += 1
7
  return count
8
str = input()
9
print(vowels(str), end='')
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
Hello, World
3
3
Passed
Test Case 2
Python Programming
4
4
Passed
Test Case 3
AEIOU
5
5
Passed
Test Case 4
The quick brown fox jumps over the lazy dog
11
11
Passed



Week 9: Programming Assignment 2

Due on 2024-09-26, 23:59 IST

Write a function that takes a string and determines if the average length of the words in the string is greater than 4. If the average word length is greater than 4, the function should return 1; otherwise, it should return 0.

Input Format:

The input consists of a single string. The string contains words separated by spaces.

Output Format:

A single integer: 1 if the average word length is greater than 4, 0 otherwise.

Example:

Input:

The quick brown fox jumps over the lazy dog

Output:

0




Your last recorded submission was on 2024-09-14, 08:50 IST
Select the Language for this assignment. 
1
def avglen(str):
2
  words = str.split(' ')
3
  avg = 0
4
  for w in words:
5
    avg += len(w)
6
  avg /= len(words)
7
  if avg > 4:
8
    return 1
9
  else :
10
    return 0
11
str = input()
12
print(avglen(str), end='')
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
The quick brown fox jumps over the lazy dog
0
0
Passed
Test Case 2
Hello world
1
1
Passed
Test Case 3
Average word length calculation
1
1
Passed
Test Case 4
Data science is fun0
1
1
Passed



Week 9: Programming Assignment 3

Due on 2024-09-26, 23:59 IST
Write a function that takes an integer n representing the number of nodes in a complete graph and returns the total number of edges in the graph.

A complete graph is a graph in which every pair of distinct nodes is connected by a unique edge.


Input Format:

The input consists of a single integer n which represents the number of nodes in the complete graph.

Output Format:

A single integer representing the total number of edges in the complete graph of n nodes.

Example:

Input:
4

Output:
6

Your last recorded submission was on 2024-09-14, 08:52 IST
Select the Language for this assignment. 
1
def edges(n):
2
  return(n*(n-1)//2)
3
n = int(input())
4
print(edges(n),end='')
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
4
6
6
Passed
Test Case 2
5
10
10
Passed
Test Case 3
6
15
15
Passed
Test Case 4
9
36
36
Passed




Week 10: Programming Assignment 1

Due on 2024-10-03, 23:59 IST

Question:

Write a program that accepts the string `para` and a positive integer `n` as input. The program should print `1` if there is at least one word in `para` that occurs exactly `n` times, and `0` otherwise.

Input Format:

- The input consists of two lines.

  - The first line contains the string `para`, which is a sequence of space-separated words.

  - The second line contains a positive integer `n`.

Output Format:

- A single integer, either `1` or `0`.

  - Print `1` if there is at least one word that occurs exactly `n` times.

  - Print `0` otherwise.

Example:

Input:

apple orange apple banana orange banana banana

2

Output:

1

Your last recorded submission was on 2024-09-26, 09:00 IST
Select the Language for this assignment. 
1
para = input()
2
n = int(input())
3
words = para.split(' ')
4
unique_words = list(set(words))
5
for w in unique_words:
6
  if words.count(w) == n:
7
    print('1', end='')
8
    break
9
else:
10
  print('0', end='')
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
apple orange apple banana orange banana banana
2
1
1
Passed
Test Case 2
cat dog elephant cat dog elephant lion
3
0
0
Passed
Test Case 3
test test test example example
2
1
1
Passed
Test Case 4
sun moon stars sun sun
1
1
1
Passed



Week 10: Programming Assignment 2

Due on 2024-10-03, 23:59 IST

Question:

Write a program that accepts a string of space-separated float numbers. The program should print the number of long tail numbers, where a float number is said to have a long tail if the number of digits after the decimal point is greater than the number of digits before the decimal point.

Input Format:

  • The input consists of a single line containing space-separated float numbers.

Output Format:

  • A single integer representing the number of long tail numbers.

Example:

Input:
12.3214 123.56 3.14159 100.1 45.6789

Output:
3

Your last recorded submission was on 2024-09-26, 09:45 IST
Select the Language for this assignment. 
1
L = input().split(' ')
2
count = 0
3
for number in L:
4
  n = number.split('.')
5
  if len(n[1]) > len(n[0]):
6
    count +=1
7
print(count, end='')
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
12.3214 123.56 3.14159 100.1 45.6789
3
3
Passed
Test Case 2
12345.678 1234.5 12.34 1.234 0.1234
2
2
Passed
Test Case 3
0.0 0.0
0
0
Passed



Week 10: Programming Assignment 3

Due on 2024-10-03, 23:59 IST

Question:

Write a program that accepts a space-separated string of integers representing a sequence of even length. The program should determine whether the sequence is left-heavy, right-heavy, or balanced. It should print:

  • -1 if the sequence is left-heavy (left half sum > right half sum).
  • 1 if the sequence is right-heavy (right half sum > left half sum).
  • 0 if the sequence is balanced (both sums are equal).

Input Format:

  • The input consists of a single line containing space-separated integers.

Output Format:

  • A single integer: -1 for left-heavy, 1 for right-heavy, or 0 for balanced.

Example:

Input:
1 2 3 4 5 6

Output:
1

Your last recorded submission was on 2024-09-26, 10:00 IST
Select the Language for this assignment. 
1
L = input().split(' ')
2
L = [int(num) for num in L]
3
left, right = 0,0
4
for i in range(len(L)//2):
5
  left +=L[i]
6
for i in range(len(L)//2,len(L)):
7
  right +=L[i]
8
if left > right:
9
  output = '-1'
10
elif left < right:
11
  output = '1'
12
elif left == right:
13
  output = '0'
14
print(output, end='')
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
1 2 3 4 5
1
1
Passed
Test Case 2
1 2 2 2
1
1
Passed
Test Case 3
10 5 1 1 2 2
-1
-1
Passed
Test Case 4
2 4 6 8 10 1 3 5 7 9
-1
-1
Passed




Week 11: Programming Assignment 1

Due on 2024-10-10, 23:59 IST

Question:

Write a program that accepts a date in MM/DD/YYYY format as input and prints the date in DD-MM-YY format. The program should retain only the last two digits of the year, replace the forward slash (/) with a dash (-), and swap the order of the month and date.

Input Format:

  • The input consists of a single line.

    • The line contains a date string in MM/DD/YYYY format.

Output Format:

  • A single string in DD-MM-YY format.

    • Print the date with the day and month swapped, the year truncated to the last two digits, and all separators replaced by dashes (-).

Example:

Input:

12/25/2024

Output:

25-12-24

Your last recorded submission was on 2024-09-27, 22:32 IST
Select the Language for this assignment. 
1
L = input().split('/')
2
print(L[1],'-', L[0], '-', L[2][2:], sep='', end='')
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
12/25/2024
25-12-24
25-12-24
Passed
Test Case 2
01/05/2001
05-01-01
05-01-01
Passed
Test Case 3
10/15/1999
15-10-99
15-10-99
Passed
Test Case 4
07/04/1776
04-07-76
04-07-76
Passed



Week 11: Programming Assignment 2

Due on 2024-10-10, 23:59 IST

Question:

Write a program that accepts a sequence of numbers separated by colons as input, and prints the common factors of all the numbers in ascending order.

Input Format:

The input consists of a single line.

The line contains a sequence of integers separated by colons.

Output Format:

Print the common factors of all the numbers, separated by spaces, in ascending order.

Example:

Input:

12:18:24

Output:
1 2 3 6

Your last recorded submission was on 2024-09-28, 11:14 IST
Select the Language for this assignment. 
1
L = input().split(':')
2
L = [int(num) for num in L]
3
common_factors = []
4
for i in range(1, min(L)+1):
5
  flag = True
6
  for n in L:
7
    if n % i == 0:
8
      continue
9
    else:
10
      flag = False
11
      break
12
  if flag == True:
13
    common_factors += [i]
14
print(' '.join(map(str,common_factors)), end='')
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
12:18:24
1 2 3 6
1 2 3 6
Passed
Test Case 2
20:30:50
1 2 5 10
1 2 5 10
Passed
Test Case 3
15:25:35
1 5
1 5
Passed
Test Case 4
8:12:16
1 2 4
1 2 4
Passed




Week 11: Programming Assignment 3

Due on 2024-10-10, 23:59 IST

Question:

You are given a specific mapping between random lowercase alphabet letters and digits. Your task is to decode a date provided in the format `DD-MM-YYYY`, where each digit is represented by a corresponding letter, and convert it back to its standard decimal format.


The mapping is as follows:

a → 0

k → 1

x → 2

y → 3

s → 4

m → 5

b → 6

d → 7

p → 8

z → 9

Input Format:

- A single line containing a date in the format `DD-MM-YYYY`, where each digit is encoded using the given letter-to-number mapping.


Output Format:

- A single line containing the decoded date in standard `DD-MM-YYYY` format.

Example:

Input:

mk-ya-kzma

Output:

15-03-1750

Your last recorded submission was on 2024-09-28, 10:44 IST
Select the Language for this assignment. 
1
L = input()
2
mapper = [ 'a', 'k', 'x', 'y', 's', 'm', 'b', 'd', 'p', 'z' ]
3
date = ''
4
for x in L:
5
  if x == '-':
6
    date += '-'
7
  else:
8
    date += str(mapper.index(x))
9
print(date, end='')
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
km-ay-kdma
15-03-1750
15-03-1750
Passed
Test Case 2
xx-ad-kdzz
22-07-1799
22-07-1799
Passed
Test Case 3
ap-kx-kpkx
08-12-1812
08-12-1812
Passed
Test Case 4
ak-ak-kpma
01-01-1850
01-01-1850
Passed



Week 12: Programming Assignment 1

Due on 2024-10-17, 23:59 IST

Question:

Write a recursive function named collatz that accepts a positive integer n as an argument, where 1 < n ≤ 32,000, and returns the number of times the Collatz function has to be applied repeatedly in order to first reach 1.

The Collatz function is defined as follows:

  • If n is even, divide n by 2.
  • If n is odd, multiply n by 3 and add 1.

The function should continue applying this process until n becomes 1, and return the number of steps taken.

Input Format:

A single integer n where 1 < n ≤ 32,000.

Output Format:

A single integer representing the number of steps required for n to reach 1.

Example:

Input:
12

Output:
9


Your last recorded submission was on 2024-10-10, 14:44 IST
Select the Language for this assignment. 
1
def collatz(n):
2
  if n == 1:
3
    return 0;
4
  else:
5
    if n%2 == 1:
6
      return 1 + collatz( 3 * n + 1 )
7
    else:
8
      return 1 + collatz(n / 2)
9
print(collatz(int(input())), end='')
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
12
9
9
Passed
Test Case 2
27
111
111
Passed
Test Case 3
19
20
20
Passed
Test Case 4
1000
111
111
Passed



Week 12: Programming Assignment 2

Due on 2024-10-17, 23:59 IST

Question:
There are `n` people who start in a happy state. The following rules determine how people move between states after each iteration:

- A person in the happy state has a 70% chance of moving to a sad state, and a 30% chance of staying in the happy state.
- A person in the sad state has a 50% chance of moving to a happy state, and a 50% chance of staying in the sad state.

Write a program that computes the number of people in the happy and sad states after 3 iterations.

Input Format:
A single integer `n` representing the number of people who start in the happy state.

Output Format:
Two integers separated by a space, where the first integer is the number of people in the happy state and the second is the number of people in the sad state after the 3rd iteration.

Example:

Input:

1000

Output:

412 588

Explanation:

State 0: 1000 0

State 1: 300 700

State 2: 440 560

State 3: 412 588


Your last recorded submission was on 2024-10-10, 15:00 IST
Select the Language for this assignment. 
1
happy = int(input())
2
sad = 0
3
for i in range(3):
4
  happy, sad = happy * 0.30 + sad * 0.50 , sad * 0.50 + happy * 0.70
5
print(int(happy),int(sad), end='')
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
1000
412 588
412 588
Passed
Test Case 2
2000
824 1176
824 1176
Passed
Test Case 3
3000
1236 1764
1236 1764
Passed



Week 12: Programming Assignment 3

Due on 2024-10-17, 23:59 IST

Problem Statement:

Write a program that accepts a positive integer n and prints the sum of all prime numbers in the range [1, n], including both endpoints. If there are no prime numbers in the given range, the program should print 0.

Input Format:

  • A single integer n, representing the upper limit of the range.

Output Format:

  • A single integer representing the sum of all prime numbers in the range [1, n]. If no prime numbers are found, output 0.

Example:

Input:

10

Output:

17

Explanation:

The prime numbers between 1 and 10 are 2, 3, 5, and 7. Their sum is 2 + 3 + 5 + 7 = 17.


Your last recorded submission was on 2024-10-10, 15:21 IST
Select the Language for this assignment. 
1
n = int(input())
2
sum = 0
3
for p in range(2, n+1):
4
  for i in range(p//2,1,-1):
5
    if p % i == 0:
6
      break
7
  else:
8
    sum += p
9
print(sum, end='')
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
6
10
10
Passed
Test Case 2
12
28
28
Passed
Test Case 3
13
41
41
Passed
Test Case 4
14
41
41
Passed




























No comments:

Post a Comment

Keep your comments reader friendly. Be civil and respectful. No self-promotion or spam. Stick to the topic. Questions welcome.