Top 15 First Round Questions For Interview of Python Programmer

Top 15 First Round Questions For Interview for Python Programmer

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn
Share on whatsapp
WhatsApp
Share on telegram
Telegram
Share on email
Email

Some instructions before we begin :-

  1. First see the question and than solve and check if solution is correct or not.
  2. There are many ways of doing a same Question, if you find another way to solve question than share with other people in comment section.
  3. If you are not able to solve questions than don’t worry see the solution and than try solving it.

Q1: Python Program to add two numbers

Solution:

# Python3 program to add two numbers
num1 = 15
num2 = 12
# Adding two nos
sum = num1 + num2
# printing values
print(“Sum of {0} and {1} is {2}” .format(num1, num2, sum))

Q2: Python Program for factorial of a number

Solution:

def factorial(n):
    if n < 0:
        return 0
   elif n == 0 or n == 1:
       return 1
   else:
        fact = 1
        while(n > 1):
                 fact *= n
                 n -= 1
       return fact
num = 5;
print(“Factorial of”,num,”is”,
factorial(num))

Q3: Python Program for simple interest

Solution:

def simple_interest(p,t,r):
    print(‘The principal is’, p)
    print(‘The time period is’, t)
    print(‘The rate of interest is’,r)

    si = (p * t * r)/100

    print(‘The Simple Interest is’, si)
    return si

simple_interest(8, 6, 8)

Q4: Python Program for compound interest

Solution:

# interest for given values.

def compound_interest(principle, rate, time):

    # Calculates compound interest
    CI = principle * (pow((1 + rate / 100), time))
    print(“Compound interest is”, CI)

# Driver Code
compound_interest(10000, 10.25, 5)

Q5: Python Program to check Armstrong
Number

Solution:

# Python program to determine whether the
number is
# Armstrong number or not
# Function to calculate x raised to the power y
def power(x, y):
if y==0:
return 1
if y%2==0:
return power(x, y/2)*power(x, y/2)
return x*power(x, y/2)*power(x, y/2)
# Function to calculate order of the number
def order(x):
# variable to store of the number
n = 0
while (x!=0):
n = n+1
x = x/10
return n

Q6: Python Program for Program to find area of a circle

Solution:

# Python program to find Area of a circle
def findArea(r):

    PI = 3.142
    return PI * (r*r);

# Driver method
print(“Area is %.6f” % findArea(5));

Q7: Python program to print all Prime
numbers in an Interval

Solution:

start = 11
end = 25
for val in range(start, end + 1):
    if val > 1:
        for n in range(2, val//2 + 2):
              if (val % n) == 0:
                      break
              else:
                      if n == val//2 + 1:
                             print(val) 

Q8: Python program to check whether a number is Prime or not

Solution:

num = 11
# If given number is greater than 1
if num > 1:
# Iterate from 2 to n / 2
for i in range(2, num//2):
     # If num is divisible by any number between
     # 2 and n / 2, it is not prime
     if (num % i) == 0:
           print(num, “is not a prime number”)
           break
else:
      print(num, “is a prime number”)
else:
      print(num, “is not a prime number”)

Q9: Python Program for How to check if a given number is Fibonacci number?

Solution:

def isPerfectSquare(x):
     s = int(math.sqrt(x))
     return s*s == x
# Returns true if n is a Fibinacci Number, else false
def isFibonacci(n):
     # n is Fibinacci if one of 5*n*n + 4 or 5*n*n – 4 or both
     # is a perferct square
     return isPerfectSquare(5*n*n + 4) or isPerfectSquare(5*n*n – 4)

# A utility function to test above functions
for i in range(1,11):
    if (isFibonacci(i) == True):
          print(i,”is a Fibonacci Number”)
   else:
          print(i,”is a not Fibonacci Number “)

Q10: Program to print ASCII Value of a
character

Solution:

# Python program to print
# ASCII Value of Character

# In c we can assign different
# characters of which we want ASCII value

c = ‘g’
# print the ASCII value of assigned character in c
print(“The ASCII value of ‘” + c + “‘ is”, ord(c))

Hope You  Would have enjoyed and learnt a lot!!!

Leave a Comment

Get your FREE Ebook on training your dog !
Enter your email address and we will send you a 100% free e-book on a simple dog game.
Limited Copy Left
Get your FREE Ebook on training your dog !
Enter your email address and we will send you a 100% free e-book on a simple dog game.
Limited Copy Left