Python Interview Questions and Answers With Code # Python
Python Interview Questions and Answers With Code # Python
Python Interview Questions and Answers With Code # Python
enter l1 number45
enter l2 number35
the sum of l1 and l2= 80
enter l1 number35.6
enter l2 number45.6
the sum of l1 and l2= 81.2
1
[19]: l1=int(input("enter a number"))
sr=l1**(1/2)## ** use for power of number
print("the square of number",sr)
enter a number49
the square of number 7.0
enter a number64.5
square root of l1: 8.031189202104505
13 12
2
13
12
13
6 kilometer to miles
[1]: # 1km = 0.621371 miles
l1=int(input("enter a km:"))
miles=l1*0.621371
print("km to miles",miles)
enter a km:10
km to miles 6.21371
enter a number0
zero
enter a number-6
negative
3
if(year%400 == 0) and (year%100==0):
print(year, "is leap year")
else:
print(year,"is not leap year")
enter a year1957
1957 is not leap year
num 3 largest
4
[7]: num=int(input("Enter the number"))
if num==1:
print("it is prime number")
if num>1:
for i in range(2,num):
if num % i==0:
print("it is not prime number")
break
else:
print("prime number")
enter anumber9
not prime number
5
23 prime number
29 prime number
31 prime number
37 prime number
[22]: 6
14 fahrenheit to celcius
[16]: fer=int(input("Enter the fahernheit="))
celcius=((fer-32)*5)/9
print(celcius," celcius")
# celcius=((fr-32)*5)/9
6
15 Find the factorial of number
like 5!=54321=120 4!=432*1=24 hint factorial me negative number nahi hote negative number ka
factorial nahi nikala jata 0!=1
[1]: num=int(input("Enter a number"))
fact=1
# condicatons we use for factorial
if num < 0:
print("factorial of less than 0 doest not exist")
if num==0:
print("factorail of 0 is ",1)
if num>0:
for i in range(1,num+1):
fact=fact*i
print("the factorial of hiven number is",fact)
Enter a number5
the factorial of hiven number is 120
[12]:
enter a number5
1
def fact(a):
if a==0:
return 1
else:
return((a)*fact(a-1))
7
16 python program to multipication of table
[2]: n=int(input("Enter a number"))
for i in range(1,11):
print(n,"x",i,"=",n*i)
Enter a number5
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
[1]: n=7
i=1
while i<=10:
print(n,"x",i,"=",n*i)
i=i+1
7 x 1 = 7
7 x 2 = 14
7 x 3 = 21
7 x 4 = 28
7 x 5 = 35
7 x 6 = 42
7 x 7 = 49
7 x 8 = 56
7 x 9 = 63
7 x 10 = 70
if num==1:
print(a)
8
else:
print(a)
print(b)
for i in range(1,num):
c=a+b
a=b
b=c
print(c)
# initialize sum
sum = 0
cube = digit ** 3
sum=sum+cube
temp //= 10
9
[13]:
# initialize sum
sum = 0
Enter a number5
15
10
Python Program to Display Powers of 2 Using Anonymous Function
** Anonymous Funaction** lamda funcation is Anonymous Funcation Becacuse its temporary
funaction means Isko alag se difine kr ne ki jarurat nahi padti hamre satament ke sath he work
karta he kam memory ka use karta he
Map fuanction particualr ” srting ke lenth count find kr tah he aur usko list formate print kr deta
he”
[9]: n=int(input("enter a number"))
result=list(map(lambda x:2**x,range(n+1))) # n=5 # 5 4 3 2 1
print(result)
enter a number5
[1, 2, 4, 8, 16, 32]
[25]: n=2
for i in range(0,5+1):
k=(n**i)
print([k],end="")
[1][2][4][8][16][32]
for i in range(n+1):
enter a number5
[1, 2, 4, 8, 16, 32]
the value of 2 raised to powe 0 is 1
the value of 2 raised to powe 1 is 2
the value of 2 raised to powe 2 is 4
the value of 2 raised to powe 3 is 8
the value of 2 raised to powe 4 is 16
the value of 2 raised to powe 5 is 32
Python Program to Find Numbers Divisible by Another Number
[45]: for i in range(1,100):
if i%13==0:
k=i
print(k,end=" ")
print(list[k],end=" ")
11
[49]: l=[39,79,48,49,88]
r=list(filter(lambda x : x%13==0,l)) # l=x for lambda
print(r)
[39]
Convert Decimal to Binary, Octal, and Hexadecimal
[51]: d= int(input("enter a number"))
print(bin(d))
print(oct(d))
print(hex(d))
# decimal 0 to 9
# bin ,oct ,hex is python inbulit function
enter a number5
0b101
0o5
0x5
Python Program to Find ASCII Value of Character
ord() inbulit Funaction python
Enter a charcatera
Ascii of value of a is 97
*
***
*****
*******
*
* *
12
* * *
* * * *
* * * * *
* * * * *
* * * *
* * *
* *
*
*****
****
***
**
*
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1
Python Program to Check Prime Number - Complete Guide | Python Tutorial
[35]:
enter a number1
prime Number
13
[ ]: num=int(input("Enter the number"))
if num==1:
print("it is prime number")
if num>1:
for i in range(2,num):
if num % i==0:
print("it is not prime number")
break
else:
print("prime number")
[7]: l=[1,2,3]
l.reverse()
print(l)
[3, 2, 1]
14
Enter String:hello
olleh
[ ]:
15