Professional Documents
Culture Documents
TechM Codes
TechM Codes
TechM Codes
Multiplication of digits
345
3*4*5 =60
print("Hello world")
str_a=str(a)
z=1
for i in str_a:
x=int(i)
z*=x
print(z)
2. Build a program for calculating and returning the sums of absolute differences between adjacent numbers in
arrays of positive integers. This must be calculated from the position determined by the current user. For
example, suppose the total number of elements is 5 and these are the elements: 12364 Then, if we decide to
start from the 3rd position or enter 3 as input, the function will occur from '3', the 3rd number in the array.
Hence, the sum would be a total of (6-3)+(4-6)= 5
Input 2:
1,2,3,6,4,6,3
Output:
10
total_sum = 0
return total_sum
# Example usage:
count=int(input("Enter how many values : ")) #count
elements =[]
for i in range(count):
b=int(input())
print(result)
3. A G.P is defined as a sequence of numbers where each element after the first is found by multiplying the
previous one by a fixed, non-zero number called the common ratio.
Determine the nth term, if the second term and third term of G.P is given.
Input:
Output:
return nth_term
# Example usage
You have been provided an encrypted ciphertext as input determine the corresponding original text, text is
always in lowercase and consists of alphabets only.
Example
input1: nrfzh
Output: quick
Explanation: Since encryption is done by replacing each letter with the letter at 3 positions to the left,
therefore to decrypt, we need to find letters at 3 positions to the right.
def decrypt_message(encrypted_text):
original_text = ""
if char.isalpha():
original_text += decrypted_char
else:
original_text += char
return original_text
# Example
encrypted_input = "nrfzh"
decrypted_output = decrypt_message(encrypted_input)
print("Output:", decrypted_output)
5. Write a program to calculate and return the sum of distances between the adjacent number in an array of
positive integers.
Note: You are expected to write code in the findTotalDistance function only which receive the first parameter
as the numbers of items in the array and second paramter as the array itself. You are not required to take the
input from the console.
Example
input 1:5
input 2: 10 11 7 12 14
Output
12
Explanation
The first parameter 5 is the size of the array. Next is an array of integers. The total of distances is 12 as per
calculation below.
10-11=1
11-7-4
7-12-5
12-14-2
total = 0
for i in range(n-1):
total+= abs(numbers[i]-numbers[i+1])
return total
n = int(input())
-----
https://www.scribd.com/document/505937158/TechMahindra-Codes
https://www.naukrimessenger.com/question-paper/tech-mahindra-coding-questions-and-answers/
Write a program to cal and return the sum of absolute diff between the adj num of positive integer from the
position entered by user.
Write a program to find the diff between the element at odd index and even index.
Write a program to return the diff between the count of odd num and even numbers.