Infosys TQ Exam Sample Questions
Infosys TQ Exam Sample Questions
Question 1: Accept two int values from user and return their product. If the product is
greater than 1000, then return their sum
Question 2: Given a range of numbers. Iterate from o^th number to the end number
and print the sum of the current number and previous number
Question 3: Accept string from the user and display only those characters which are
present at an even index
For example str = "pynative" so you should display ‘p’, ‘n’, ‘t’, ‘v’.
Question 4: Given a string and an int n, remove characters from string starting from
zero upto n and return a new string
Note: n must be less than length of string. For example, removeChars("pynative", 4) so
output must be “tive”.
Question 5: Given a list of ints, return True if first and last number of a list is same
Question 6: Given a list of numbers, Iterate it and print only those numbers which are
divisible of 5
Question 7: Return the number of times that the string “Emma” appears anywhere in
the given string
Given string is “Emma is a good developer. Emma is also a writer” and output should be
2.
Question 8: Print the following pattern
● 1
● 2 2
● 3 3 3
● 4 4 4 4
● 5 5 5 5 5
Question 9: Reverse a given number and return true if it is the same as the original
number
Question 10: Given a two list of ints create a third list such that should contain only odd
numbers from the first list and even numbers from the second list
Question 1: Given a string of odd length greater 7, return a string made of the middle
three chars of a given String
For example: –
● getMiddleThreeChars("JhonDipPeta") → "Dip"
● getMiddleThreeChars("Jasonay") → "son"
Question 2: Given 2 strings, s1 and s2, create a new string by appending s2 in the
middle of s1
For example: –
Question 4: arrange String characters such that lowercase letters should come first
Given input String of combination of the lower and upper case arrange characters in
such a way that all lowercase letters should come first.
For Example: –
● lowercaseFirst("PyNaTive") = aeiNPTvy
Question 5: Given an input string Count all lower case, upper case, digits, and special
symbols
For example: –
Note: create a third-string made of the first char of the last char of b, the second char of
the second last char of b, and so on. Any leftover chars go at the end of the result.
For Example: –
We’ll say that a String s1 and s2 is balanced if all the chars in the string1 are there in
s2. characters position doesn’t matter.
For Example: –
Question 8: Find all occurrences of “USA” in given string ignoring the case
For Example: –
Question 9: Given a string, return the sum and average of the digits that appear in the
string, ignoring all other characters
For Example: –
Question 10: Given an input string, count occurrences of all characters within a string
For Example:
● count("pynativepynvepynative") = {'p': 3, 'y': 3, 'n': 3, 'a':
2, 't': 2, 'i': 2, 'v': 3, 'e': 3}
Python Data Structure
Question 1: Given a two list. Create a third list by picking an odd-index element from the first list
and even index elements from second.
For Example:
Question 2: Given an input list removes the element at index 4 and add it to the 2nd position
and also, at the end of the list
Question 3: Given a list slice it into a 3 equal chunks and rever each list
Expected Outcome:
For example: list = [10, 20, 30, 10, 20, 40, 50]
Question 5: Given a two list of equal size create a set such that it shows the element from both
lists in the pair
For example:
Question 6: Given a following two sets find the intersection and remove those elements from
the first set
For Example:
For Example:
Expected Outcome:
Question 8: Iterate a given list and Check if a given element already exists in a dictionary as a
key’s value if not delete it from the list
Given:
Expected Outcome:
● after removing unwanted elemnts from list [47, 69, 76, 97]
Question 9: Given a dictionary get all values from the dictionary and add it in a list but don’t add
duplicates
Given:
Question 10: Remove duplicate from a list and create a tuple and find the minimum and
maximum number
For Example:
Expected Outcome:
Python Database
Implement the functionality to connect to the database and print its version.
def g etDbConnection():
#code to Get Database connection
def c loseDbConnection(connection):
#Code Close Database connection
def r eadDbVersion():
# Execute SQL query to print database server version
readDbVersion()
Implement the functionality to read the details of a given doctor from doctor table
and Hospital from hospital table. i.e., read records from Hospital and Doctor
Table as per given hospital Id and Doctor Id and display hospital and doctor
information.
def r eadHospitalDetails(hospital_Id):
#Read data from Hospital table
def r eadDoctorDetails(doctor_Id):
# Read data from Doctor table
readHospitalDetails(2)
readDoctorDetails(105)
Hospital Id: = 2
Hospital Name: = Cleveland Clinic
Bed Count: = 400
Implement the functionality to create a list of doctors as per given Speciality and
salary greater than as per the input amount.
getSpecialistDoctorsList("Garnacologist", 30000)
Implement the functionality to fetch all the doctors within the given Hospital Id.
You must also display the hospital name of a doctor.
def g etHospitalName(HospitalId):
#Fetch Hospital Name using Hospital Id
def G etDoctordWithinHospital(hospitalId):
#Fetch All doctors within given Hospital
You know as of now Experience column value for each doctor is null. Implement
the functionality to update experience of a given doctor in years.
def g etDoctorJoiningDate(DoctorId):
#Get Doctor's joining date using doctor ID
def u pdateDoctorsExperience(doctorId):
#Update Doctor Experience in Years