0% found this document useful (0 votes)
3 views7 pages

Deloitte Python Coding Questions

The document lists 20 important Python coding interview questions frequently asked in Deloitte interviews, each accompanied by a detailed solution that emphasizes logic-building without using built-in functions. Topics include reversing numbers, checking for prime numbers, generating Fibonacci series, and more. The document serves as a practical guide for candidates preparing for technical interviews.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views7 pages

Deloitte Python Coding Questions

The document lists 20 important Python coding interview questions frequently asked in Deloitte interviews, each accompanied by a detailed solution that emphasizes logic-building without using built-in functions. Topics include reversing numbers, checking for prime numbers, generating Fibonacci series, and more. The document serves as a practical guide for candidates preparing for technical interviews.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Top 20 Deloitte Python Coding Interview Questions

This PDF contains 20 important Python coding interview questions commonly asked in Deloitte interviews. Each solution
avoids direct shortcut functions and focuses on logic-building fundamentals.

1. Reverse a Number

Write a Python program to reverse a given integer without using built-in reverse functions.

Code:
num = 12345
temp = num
rev = 0

while temp > 0:


digit = temp % 10
rev = rev * 10 + digit
temp = temp // 10

print("Reversed Number:", rev)

Expected Output Reversed Number: 54321

2. Check Prime Number

Write a Python program to check whether a number is prime.

Code:
num = 29
count = 0

for i in range(1, num + 1):


if num % i == 0:
count += 1

if count == 2:
print("Prime Number")
else:
print("Not a Prime Number")

Expected Output Prime Number

3. Fibonacci Series

Write a Python program to print Fibonacci series up to n terms.

Code:
n = 10
a = 0
b = 1

print(a)
print(b)

for i in range(2, n):


c = a + b
print(c)
a = b
b = c

Expected Output 0 1 1 2 3 5 8 13 21 34

4. Palindrome Number

Check whether a number is palindrome.

Code:
num = 121
temp = num
rev = 0

while temp > 0:


digit = temp % 10
rev = rev * 10 + digit
temp = temp // 10

if rev == num:
print("Palindrome")
else:
print("Not Palindrome")

Expected Output Palindrome

5. Factorial of a Number

Find factorial using loop.

Code:
num = 5
fact = 1

for i in range(1, num + 1):


fact = fact * i

print("Factorial:", fact)

Expected Output Factorial: 120

6. Armstrong Number

Check whether a number is Armstrong number.

Code:
num = 153
temp = num
sum1 = 0

while temp > 0:


digit = temp % 10
sum1 = sum1 + (digit * digit * digit)
temp = temp // 10

if sum1 == num:
print("Armstrong Number")
else:
print("Not Armstrong Number")

Expected Output Armstrong Number


7. Swap Two Numbers

Swap two numbers without using third variable.

Code:
a = 10
b = 20

a = a + b
b = a - b
a = a - b

print("a =", a)
print("b =", b)

a = 20
Expected Output b = 10

8. Largest Among Three Numbers

Find the largest among three numbers.

Code:
a = 10
b = 50
c = 30

if a > b and a > c:


print(a, "is largest")
elif b > c:
print(b, "is largest")
else:
print(c, "is largest")

Expected Output 50 is largest

9. Count Digits in a Number

Count total digits in a number.

Code:
num = 987654
count = 0

while num > 0:


count += 1
num = num // 10

print("Digits:", count)

Expected Output Digits: 6

10. Sum of Digits

Find sum of digits of a number.


Code:
num = 1234
sum1 = 0

while num > 0:


digit = num % 10
sum1 = sum1 + digit
num = num // 10

print("Sum:", sum1)

Expected Output Sum: 10

11. Check Even or Odd

Check whether a number is even or odd.

Code:
num = 15

if num % 2 == 0:
print("Even")
else:
print("Odd")

Expected Output Odd

12. Print Multiplication Table

Print multiplication table of a number.

Code:
num = 5

for i in range(1, 11):


print(num, "x", i, "=", num * i)

Expected Output 5 x 1 = 5 ... 5 x 10 = 50

13. Check Leap Year

Check whether a year is leap year.

Code:
year = 2024

if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):


print("Leap Year")
else:
print("Not Leap Year")

Expected Output Leap Year

14. Find GCD


Find GCD of two numbers.

Code:
a = 36
b = 60

while b != 0:
temp = b
b = a % b
a = temp

print("GCD:", a)

Expected Output GCD: 12

15. Decimal to Binary

Convert decimal number to binary.

Code:
num = 10
binary = ""

while num > 0:


rem = num % 2
binary = str(rem) + binary
num = num // 2

print("Binary:", binary)

Expected Output Binary: 1010

16. Linear Search

Search an element using linear search.

Code:
arr = [10, 20, 30, 40, 50]
key = 30
found = 0

for i in arr:
if i == key:
found = 1

if found == 1:
print("Element Found")
else:
print("Element Not Found")

Expected Output Element Found

17. Bubble Sort

Sort elements using bubble sort.

Code:
arr = [5, 2, 8, 1, 9]

for i in range(len(arr)):
for j in range(0, len(arr) - i - 1):
if arr[j] > arr[j + 1]:
temp = arr[j]
arr[j] = arr[j + 1]
arr[j + 1] = temp

print(arr)

Expected Output [1, 2, 5, 8, 9]

18. Matrix Addition

Add two matrices.

Code:
a = [[1, 2], [3, 4]]
b = [[5, 6], [7, 8]]
result = [[0, 0], [0, 0]]

for i in range(2):
for j in range(2):
result[i][j] = a[i][j] + b[i][j]

print(result)

Expected Output [[6, 8], [10, 12]]

19. Count Vowels

Count vowels in a string.

Code:
text = "deloitte"
count = 0

for ch in text:
if ch == 'a' or ch == 'e' or ch == 'i' or ch == 'o' or ch == 'u':
count += 1

print("Vowels:", count)

Expected Output Vowels: 4

20. Second Largest Number

Find second largest number in a list.

Code:
arr = [10, 40, 20, 90, 60]

largest = arr[0]
second = arr[0]

for i in arr:
if i > largest:
second = largest
largest = i
elif i > second and i != largest:
second = i

print("Second Largest:", second)


Expected Output Second Largest: 60

You might also like