Python Interview Questions Set - 9 Released
Intermediate Level
Python Program to Reverse a Number
ur_input = int(input("Enter Some Number:"))
def reverseNumber(num):
if type(num) == str:
return int(num[::-1])
else:
temp = 0
while num != 0:
last_digit = num % 10
temp = temp * 10 + last_digit
num //= 10
return temp
res = reverseNumber(ur_input)
Python Program to Check if a Number is a Palindrome
ur_input = int(input("Enter Some Number: "))
def isNumPalindrome(num):
if reverseNumber(num) == num:
return f"{num} is Palindrome"
else:
return f"{num} is not Palindrome"
res = isNumPalindrome(ur_input)
Python Program to check if the given string ins palindrome or not
ur_input = input("Enter Some Number: ").lower()
def isStrPalindrome(str_):
rev_str = str_[::-1]
if rev_str == str_:
return f"{str_} is Palindrome String"
else:
return f"{str_} is not Palindrome String"
res = isStrPalindrome(ur_input)
Python Program to print the multiplication table without using multiplication (*) Operator
ur_input = int(input("Enter Some Number: "))
def printMultiNumber(num):
for i in range(1,11):
temp = 0
for _ in range(i):
temp += num
print(temp)
printMultiNumber(ur_input)
Python Program to Check Whether a Given Number is Perfect Number
ur_input = int(input("Enter Some Number: "))
def isPerfectNumber(num):
divisors = [i for i in range(1,num) if num%i==0]
if sum(divisors) == num:
return f"{num} is the Perfect Number"
else:
return f"{num} is not Perfect Number"
res = isPerfectNumber(ur_input)
Recent Comments
Archives
Categories
Categories
- Inspiration (1)
- Style (1)
- Technical Blog (18)
- Tips & tricks (2)
- Uncategorized (21)