Python Interview Question Programs

Python Interview Question Programs – Learn Python with me

Welcome to our blog and our tutorial series, Learn Python with me. Today in this post, we will discuss the most common Python Interview Question programs asked in the interviews. If you are looking for a job or career based on the Python programming language, this post will benefit you. We will keep updating this space whenever we encounter any vital program interviewers who might ask in the interviews.

Prime Number Python Interview Question Programs

Please find below the Prime Number Program in Python

#program to display the prime numbers
number=int(input("Enter the maximum number"))
#the code above takes input from user's keyboard and stores the value in variable b
print("The list of prime numbers till {0} are below: ".format(number))
for num in range(2, number+1):
    if num>1:
        for a in range(2,num):
            if(num%a)==0:
                break
        else:
            print(num)

Output

Enter the maximum number20
The list of prime numbers till 20 are below:
2
3
5
7
11
13
17
19

Fibonacci Number series program in Python

Please find below the Fibonacci Number series program in Python

#program to display the fibonacci series for a desired number
number=int(input("Enter a number"))
fib1=0 #first fibonacci number
fib2=1 #second fibonacci number
count=2 #to count the number of fibonaccis
if number==1:
    print(fib1)
elif number==2:
    print(fib1,'\n',fib2,sep='')
else:
    print(fib1,'\n',fib2,sep='')
    while count<number:
        f=fib1+fib2
        print(f)
        fib1,fib2=fib2,f
        count+=1

Output

Enter a number9
0
1
1
2
3
5
8
13
21

Palindrome Program in Python

Please find below the Palindrome Program in Python.

#program to test if a value is palindrome or not
string1=str(input("Enter the string"))
#enter the string from keyboard
string1=string1.casefold()
#make the string suitable for caseless comparison
string2=reversed(string1)
#reverse the string

#let us check if both strings are same
if list(string1)==list(string2):
    print("{0} is a palindrome".format(string1))
else:
    print("{0} is not a palindrome".format(string2))

Output

Enter the stringTenet
tenet is a palindrome

Factorial of a number Program in Python

Please find below the “Factorial of a number Program in Python”.

#program to find the factorial of a number
import math
number=int(input("Enter the number: "))
b=math.factorial(number)
print(b)

Output

Enter the number: 7
5040
Scroll to Top