# Python Interview Questions Set - 11 Released

## Intermediate Level

## Write the python program to print the numbers in the range without using loops

ur_input = int(input("Enter Some Number: "))

def printNums(num):

if num > 0:

printNums(num-1)

print(num)

printNums(ur_input)

## Write the python program to print the numbers in range in descening order without using loops

ur_input = int(input("Enter Some Number: "))

def printRevNums(num):

if num > 0:

print(num)

printRevNums(num-1)

printRevNums(ur_input)

## Write the python program to check if two numbers are amicable or not

Amicable numbers are two different numbers so related that the sum of the proper divisors (excluding the number itself) of each is equal to the other number. For example, 220 and 284 are amicable numbers because:

The proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55, and 110, and their sum is 284.

The proper divisors of 284 are 1, 2, 4, 71, and 142, and their sum is 220.

a, b = map(int, input("Enter Two Numbers: ").split())

def is_amicable(num1, num2):

num1_divs = [i for i in range(1, num1) if num1%i==0]

num2_divs = [i for i in range(1, num2) if num2%i==0]

```
```

` if sum(num1_divs) == num2 and sum(num2_divs) == num1:`

print(f"The Numbers are Amicable")

else:

print(f"The Numbers are not Amicable")

is_amicable(a,b)

## Write the python program to check if the number expressed in the power of two or not

import math

ur_input = int(input("Enter Some Number: "))

def is_power_two(num):

is_true = math.log2(num).is_integer()

```
```

` if is_true:`

print(f"{num} can be expressed in the form of 2's power")

else:

print(f"{num} can not be expressed in the form of 2's power")

is_power_two(ur_input)

## Write the python program to swap the two numbers

Case One -- without using any variable

a, b = map(int, input("Enter Two Numbers:").split())

print("Before Swaping")

print(f"a is {a}")

print(f"b is {b}")

```
```a, b = b, a

`print("After Swaping")`

print(f"a is {a}")

print(f"b is {b}")

Case Two -- using exta variable

a, b = map(int, input("Enter Two Numbers:").split())

print("Before Swaping")

print(f"a is {a}")

print(f"b is {b}")

```
```c = a

a = b

b = c

`print("After Swaping")`

print(f"a is {a}")

print(f"b is {b}")

### Recent Comments

### Archives

### Categories

### Categories

- Inspiration (1)
- Style (1)
- Technical Blog (18)
- Tips & tricks (2)
- Uncategorized (21)