Interview Details:
- Position Title: Automation Test Engineer
- Interview schedule month: October – 2023
- Mode of Interview: Microsoft Teams
- Skills: Python/Advanced Python and Selenium/Behave/Playwright
- Experience Required: 3+
Interview Questions and Answers:
Q1. Calculate and provide the results for the following mathematical expressions
a) 7/5
b) 7//5
c) 7%5
Q2. Given the following input:
List 1 = [10, 20, 30, 40]
List 2 = [100, 200, 300, 400]
Please write code to generate the following output:
10 100
20 200
30 300
40 400
Solution
List1 = [10, 20, 30, 40]
List2 = [100, 200, 300, 400]
for item1, item2 in zip(List1, List2):
print(item1, item2)
# Without zip
List1 = [10, 20]
List2 = [100, 200]
for i in range(len(List1)):
item1 = List1[i]
item2 = List2[i]
print(item1, item2)
Q3. Please review the following code and let me know if you identify any issues. If discrepancies exist, provide a solution for resolving them
Code:
List1 = [10, 20, 30]
List2 = [100, 200, 300, 400]
Desired Output:
10 100
20 200
30 300
Solution
min_length = min(len(List1), len(List2))
for i in range(min_length)
item1 = List1[i]
item2 = List2[i]
print(item1, item2)
Q4.Can you write the above code(Q3 Solution) in fewer lines?
See solution
List1 = [10, 20, 30]
List2 = [100, 200, 300, 400]
min_length = min(len(List1), len(List2))
for i in range(min_length):
print(List1[i], List2[i])
Q5. Create function amount of time takes the above code(Q4 Solution) to run.
Solution
import time
def measure_execution_time():
start_time = time.time() # Record the start time
List1 = [10, 20, 30]
List2 = [100, 200, 300, 400]
min_length = min(len(List1), len(List2))
for i in range(min_length):
print(List1[i], List2[i])
end_time = time.time() # Record the end time
execution_time = end_time - start_time # Calculate the execution time
return execution_time
# Call the function to measure execution time
time_taken = measure_execution_time()
print(f"Execution time: {time_taken:.6f} seconds")