ProjectWithSourceCodes
1.04K subscribers
406 photos
8 videos
142 files
1.57K links
Free Source Code Projects for Students 🚀 | Python | Java | Android | Web Dev | AI/ML | Final Year Projects | BCA • BTech • MCA | Interview Prep | Job Alerts

Website: https://updategadh.com
Download Telegram
Top 10 Python Coding Interview Questions with Answers – Part 1

━━━━━━━━━━━━━━━━━━━━━━

Q1. Write a Python program to reverse a string.

text = "Python"
print(text[::-1])


Output: nohtyP

Q2. Write a Python program to check whether a number is even or odd.

num = 15

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


Output: Odd

Q3. Write a Python program to find the largest number in a list.

numbers = [10, 45, 23, 89, 12]
print(max(numbers))


Output: 89

Q4. Write a Python program to check a palindrome string.

text = "madam"

if text == text[::-1]:
print("Palindrome")
else:
print("Not Palindrome")


Output: Palindrome

Q5. Write a Python program to calculate factorial.

n = 5
fact = 1

for i in range(1, n + 1):
fact *= i

print(fact)


Output: 120

Q6. Write a Python program to print the Fibonacci series.

a, b = 0, 1

for i in range(7):
print(a, end=" ")
a, b = b, a + b


Output: 0 1 1 2 3 5 8

Q7. Write a Python program to remove duplicates from a list.

numbers = [1, 2, 2, 3, 4, 4, 5]
result = list(dict.fromkeys(numbers))
print(result)


Output: [1, 2, 3, 4, 5]

Q8. Write a Python program to count vowels in a string.

text = "interview"
count = 0

for ch in text:
if ch in "aeiou":
count += 1

print(count)


Output: 4

Q9. Write a Python program to check a prime number.

n = 17
is_prime = n > 1

for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
is_prime = False
break

print("Prime" if is_prime else "Not Prime")


**Output:** Prime

Q10. Write a Python program to find the second largest unique number.

numbers = [10, 30, 20, 50, 40]
unique = sorted(set(numbers))
print(unique[-2])


Output: 40

━━━━━━━━━━━━━━━━━━━━━━

SAVE THIS POST FOR YOUR CODING INTERVIEW PREPARATION

NEXT PART: Python Coding Interview Questions – Part 2

UPDATEGADH | Technology Tutorials and Projects

Join Telegram: https://t.me/Projectwithsourcecodes

#PythonInterview #CodingInterview #PythonProgramming #CodingQuestions #PlacementPreparation #BCAStudents #MCAStudents #UPDATEGADH
👍1
Top 10 Python Coding Interview Questions with Answers – Part 2

━━━━━━━━━━━━━━━━━━━━━━

Q11. Write a Python program to swap two numbers without using a third variable.

a = 10
b = 20

a, b = b, a

print(a, b)

Output: 20 10

Q12. Write a Python program to find the sum of digits of a number.

num = 12345
total = 0

while num > 0:
total += num % 10
num //= 10

print(total)

Output: 15

Q13. Write a Python program to check whether a number is an Armstrong number.

num = 153
total = sum(int(digit) ** 3 for digit in str(num))

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

**Output:** Armstrong Number

Q14. Write a Python program to find common elements in two lists.

a = [1, 2, 3, 4]
b = [3, 4, 5, 6]

print(list(set(a) & set(b)))

Output: [3, 4]

Q15. Write a Python program to count the frequency of each character.

text = "python"
frequency = {}

for char in text:
frequency[char] = frequency.get(char, 0) + 1

print(frequency)

Output: {'p': 1, 'y': 1, 't': 1, 'h': 1, 'o': 1, 'n': 1}

Q16. Write a Python program to find the smallest number in a list.

numbers = [45, 12, 78, 5, 23]

print(min(numbers))

Output: 5

Q17. Write a Python program to check whether two strings are anagrams.

a = "listen"
b = "silent"

if sorted(a) == sorted(b):
print("Anagram")
else:
print("Not Anagram")

Output: Anagram

Q18. Write a Python program to find the missing number in a sequence from 1 to n.

numbers = [1, 2, 3, 5, 6]
n = 6

missing = n * (n + 1) // 2 - sum(numbers)

print(missing)

Output: 4

Q19. Write a Python program to sort a list without using sort().

numbers = [5, 2, 8, 1, 3]

for i in range(len(numbers)):
for j in range(i + 1, len(numbers)):
if numbers[i] > numbers[j]:
numbers[i], numbers[j] = numbers[j], numbers[i]

print(numbers)

Output: [1, 2, 3, 5, 8]

Q20. Write a Python program to find the sum of all even numbers in a list.

numbers = [1, 2, 3, 4, 5, 6]

total = sum(num for num in numbers if num % 2 == 0)

print(total)

Output: 12

━━━━━━━━━━━━━━━━━━━━━━

SAVE THIS POST FOR YOUR CODING INTERVIEW PREPARATION

NEXT PART: Python Coding Interview Questions – Part 3

UPDATEGADH | Technology Tutorials and Projects

Join Telegram: https://t.me/Projectwithsourcecodes

#PythonInterview #CodingInterview #PythonProgramming #CodingQuestions #PlacementPreparation #BCAStudents #MCAStudents #UPDATEGADH
👍1