Monday, 2 September 2019

The Joy of Computing using Python: Assignment 6


1 point
1. What is the output of the following program?
x = "abcdef"
i = "a"
while i in x:
print(i, end = " ")
 
 
 
 
1 point
2. Which of the following arithmetic operators can be used with strings?
 
 
 
 
1 point
3. What is the output of the following code snippet?
line = "What will have so will"
L = line.split('a')
for i in L:
    print(i, end=' ')

[‘What’, ‘will’, ‘have’, ‘so’, ‘will’]
 
 
 
1 point
4. Fill in the code to complete the following function for computing factorial:
def factorial(n):
  if n == 0:
    return 1
  else:
    return .......
 
 
 
 
1 point
5. A palindrome is a word, number, phrase, or other sequence of characters which reads the same backward
as forward. Fill in the code to complete the following function for checking whether a string is a palindrome.
def isPalindrome(s):
  if len(s) != 1:
    return True
  elif s[0] != s[-1]:
    return False
  else:
    return isPalindrome(s.substring(1, len(s) - 1))
 
 
 
 
1 point
6. What is the output of the following recursive function?
def test(i,j):
  if(i==0):
    return j
  else:
    return test(i-1,i+j)
print(test(4,7))
 
 
 
 
1 point
7. What is the game strategy used in the Tic Tac Toe game?
 
 
 
 
1 point
8. What does the following function do?
def fun(n):
  if (n == 0 or n == 1):
    return n
  if (n%3 != 0):
    return 0
  return fun(n/3)
 
 
 
 
1 point
9. Which of the following statements is correct regarding recursion and iteration?
 
 
 
 
1 point
10. If COMPUTER is denoted as KPDITWQC and SCIENCE is denoted as YKHQLKQ, how is SET denoted by this encoding scheme?
 
 
 
 

6 comments: