Skip to content

Latest commit

 

History

History
146 lines (122 loc) · 3.05 KB

File metadata and controls

146 lines (122 loc) · 3.05 KB
  1. What is the result of shifting every letter in a given word by the value? ![[Pasted image 20231029094805.jpg]]

    • Shift every letter in a given word by value. ✓
    • Shift every letter in a given word by 1.
    • Shift every letter in a given word by 26.
    • Returns the same word.
  2. In the list L = [4, 6, 7, 4, 6, 2, 1], what is the index of element '7'?

    • 0
    • 1
    • 2✓
    • 3
  3. Which of the following is true about recursion?

    • Recursion always performs better than non-recursive code.
    • Recursive code is easier to debug. ✓
    • The base case is necessary for recursion. ✓
    • Recursive code can be shorter than non-recursive code. ✓
  4. What will be the output of the following program? ![[Pasted image 20231029094851.jpg]]

    • Calculating sum of first n terms.
    • Calculating product of first n terms. ✓
    • Calculating power of first n terms.
    • Calculating sum of last n terms.
  5. In Caesar cipher, the mediator needs to make a maximum of how many trials to break the code?

    • 1
    • 26 ✓
    • No trial needed
    • 10
  6. What is the output of the following program? ![[Pasted image 20231029094906.jpg]]

    • 3628800
    • Runs into an infinite loop ✓
    • 55
    • Syntax error
  7. What's the correct code for Binary search?

  • ![[Pasted image 20231029094921.jpg]]
  • ![[Pasted image 20231029094950.jpg]]
  • ![[Pasted image 20231029094954.jpg]] ✓
  • ![[Pasted image 20231029095002.jpg]]
  1. Which of the following is TRUE about MIN-MAX strategy?

    • Maximize the chances of your winning and minimize the chances of the opponent winning. ✓
    • The game with min-max strategy can never be drawn.
    • Minimize the chances of your winning and maximize the chances of the opponent winning.
    • All of the above are true.
    • Correct Answer: Maximize the chances of your winning and minimize the chances of the opponent winning.
  2. A program that is written recursively cannot be written in a non-recursive manner.

    • True
    • False✓
  3. What will be the output of the following program? ![[Pasted image 20231029095054.jpg]]

**********
*********
********
*******
******
*****
****
***
**
*
*********
*******
*****
***
*
  •  Runs into infinite loop
**********

********

******

****

**

*

✓ correct answer is The 4th option


Programming Assignment 1

N = int(input())
L = [int(i) for i in input().split()]
K = int(input())
print(sorted(L).index(L[K-1])+1+0,end="")

Programming Assignment 2

S = input()
import string


low = string.ascii_lowercase
cap = string.ascii_uppercase

ans  = ''

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

Programming Assignment 3

def whole(n):
    if n==0:
        return 0
    else:
        return n+whole(n-1)
 
N = int(input())
print(whole(N))