TCS NQT 2021 Coding Question Asked On 21 Feb 2021 and their Solution in Python


Que 1. Find the circumference of a cricket ground when r >=22 and r<=30 also answer will be at two decimal places and if  "r" is not in range print "Radius is Wrong". If you choose c language pie value is given as 3.14159 and not in the case of Python.

r = int(input())
pie=3.14159
if r>=22 and r<=30:
  print(round(r*r*pie,2))
else:
  print("Radius is Wrong")
Sample Input 1 :22
OutPut: 1520.53
Input 2 : 30
output: Radius is Wrong

Que 2. Take a String "s" and convert the alphabet in reverse order like a=z , b= x and so on. For example Input: abcd Output: zxyw (They gave a table in which all alphabet are in lower case also space remain same )

a b c d e f g h i j k l m n o p q r s t u v w x y z
z y x w v u t s r q p o n m l k j i h g f e d c b a

In my solution space's value is also converting  so it is not accurate   
s=input()
sa=''
for i in s:
  if ord(i)>=92 & ord(i)<=109:
    r=(chr(122-ord(i)+97))
    sa=sa+r
else:
  pass
print(sa)
input:hello
output:svool