The Joy Of Computing Using Python Online Programming Test April 2022:- In This Article, we have helped with the online programming test of The Joy Of Computing Using Python.

## The Joy Of Computing Using Python Online Programming Test Answers April 2022 Set A [10 AM to 1 PM]

**Q1.** Ramneet has a long string S and he wants to analyze that string. But there are are so many adjacent duplicates in that string and Ramneet wants to get rid from those duplicates before analyzing. Help Ramneet by writing a function removeAdjacent which accepts a string S and return a new string after removing all adjacent duplicates.

Code:-

```
a=input()
b=''
for i in a:
if i not in b:
b+=i
print(b,end='')
```

**Q2. **Given a string S, write a function to swap vowels from the beginning of the string with the vowels at the end of the string. For example 1st vowel should be swapped with last vowel, second vowel should be swapped with second last and so on.

Code:-

```
def isVowel(c):
if (c == 'a' or c == 'A' or c == 'e' or
c == 'E' or c == 'i' or c == 'I' or
c == 'o' or c == 'O' or c == 'u' or c == 'U'):
return True
return False
def reverserVowel(string):
j = 0
vowel = [0] * len(string)
string = list(string)
for i in range(len(string)):
if isVowel(string[i]):
vowel[j] = string[i]
j += 1
for i in range(len(string)):
if isVowel(string[i]):
j -= 1
string[i] = vowel[j]
return ''.join(string)
string = input()
print(reverserVowel(string))
```

**Q3. **Accept a string of length three as input and print all possible three-letter strings that can be formed using the characters in the original string. Print the strings in alphabetical order, one string on each line. You can assume that all characters in the input string will be unique.

Code:-

```
n = input()
n = list(n)
n = sorted(n)
for i in range(len(n)):
for j in range(len(n)):
for k in range(len(n)):
print(n[i],end='')
print(n[j],end='')
print(n[k],end='')
print()
```

**Q4. **Ram has a weight balancer and a set of weights on one side, let’s say side 1, of the balancer. He wants to balance the balancer in such a way that every time he pulls out the largest weight from side 1 and puts it to the other side, let’s say side 2. He continues doing that until the weight of both the sides becomes equal or the side 2 becomes slightly heavy from side 1. Count the total number of times Ram has to shift weights.

Code:-

```
m.sort()
l = len(m)
for k in range(l):
if sum(m[0:l-k-1]) <= sum(m[-1-k:]):
print(k+1,end="")
break
```

## The Joy Of Computing Using Python Online Programming Test Answers April 2022 Set B [8 PM to 11 PM]

**Q1.** You are given a list nums, write a program to rotate the list nums towards right if k is positive or towards left if k is negative.(see explanation more description)

Code:-

```
n=len(nums)
if k>0:
k=k%n
x=[]
for i in range(0, n):
if(i < k):
x.append(nums[n + i - k])
else:
x.append(nums[i - k])
print(x, end='')
else:
mod = k % n
x=[]
for i in range(n):
x.append(nums[(mod + i) % n])
print(x,end='')
```

**Q2.** write a program which shifts all lowercase letters by -9 position, all uppercase letters by +3 position, white space as ‘!’, and integers in -5 position. consider integer string starting from 0 and ending at 9.

Code:-

```
st = input()
nst = ""
for i in st:
if(ord(i) >=65 and ord(i) <=90):
if(ord(i)+3>90):
nst += chr(ord(i)+3-26)
else:
nst += chr(ord(i)+3)
elif(ord(i) >=97 and ord(i) <=122):
if(ord(i)-9<97):
nst += chr(ord(i)-9+26)
else:
nst += chr(ord(i)-9)
elif(ord(i) >=48 and ord(i) <=57):
if(ord(i)-5<48):
nst += chr(ord(i)-5+10)
else:
nst += chr(ord(i)-5)
elif(ord(i) == 32):
nst += chr(ord(i)+1)
else:
nst+=i
print(nst)
```

**Q3. **Accept a string of length two as input and print all possible two-letter strings that can be formed using the characters in the original string. Print the strings in alphabetical order, one string on each line. You can assume that all characters in the input string will be unique.

Code:-

```
a=input()
a=sorted(a)
for i in a:
for j in a:
print(i,end='')
print(j)
```

**Q4.** Yash is obsessed with prime numbers but he only wants to display pair of special prime numbers. He is only interested in the pair (a, b) where a and b are prime and b is one or two more than a. Yash is given an integer n, help Yash to print all pairs till n.

Code:-

```
n=int(input())
a=[]
for i in range(2,n+1):
count=0
for j in range(1,i+1):
if i%j==0:
count+=1
if count==2:
a.append(i)
for k in range(len(a)-1):
if((a[k+1]-a[k])<3):
print('(',end='')
print(a[k],end='')
print(',',a[k+1],end='')
print(')')
```

The Joy Of Computing Using Python Online Programming Test Answers April 2022:- In This Article, we have helped with the online programming test of The Joy Of Computing Using Python.