#1. cubic of no.
for 15 to 20
import math as m
for i in range(15,21,1):
a=m.pow(i,3)
print(a)
print()
#2. without using multiplication method multiple the no
x=int(input("enter a no:"))
y=int(input("enter a no:"))
m=0
while x>0:
m+=y
x-=1
print(m)
OR
x=int(input("enter a no:"))
y=int(input("enter a no:"))
m=0
for i in range(x):
m+=y
print(m)
#3. sum of individual digit
s=0
num=int(input("enter a no :"))
while num>0:
y=num%10
num=num//10
s+=y
print(s)
#4. count vowel and consonant
sen=input("enter a sentence :")
c=0
v=0
s=sen.replace(" ","")
s1=s.lower()
L=["a","e","i","o","u"]
for ch in s1:
if ch in L:
v+=1
else:
c+=1
print("no of vowels : ",v)
print("no of consonant : ",c)
#5. example of nested loop
for i in range(1,4,1):
for j in range(1,4,1):
print(i,j)
print()
#6. sum of factorial series
import math as m
a=int(input("enter a no:"))
x=int(input("enter a no:"))
s=0
for n in range(1,x+1,1):
a1=m.pow(a,n)
y=m.factorial(n)
f=a1/y
s+=f
print(s)
OR
def power(a,b):
return(a**b)
def factorial(n):
f=1
for i in range(n,1,-1):
f*=i
return f
# main program
x=int(input("enter a no :"))
y=int(input("enter a no :"))
s=0
for i in range(1,y+1):
s+=power(x,i)/factorial(i)
print(s)
#7.decimal -> hexa , binary and octal number
x=int(input("enter a no :"))
print("octal number :",oct(x))
print("binary number :",bin(x))
print("hexa decimal number :",hex(x))
#8.no. of word of having a alphabhet
x=input("enter a sentence : ")
s=0
a=x.replace(" ","")
a1=a.lower()
h=["a"]
for i in a1:
if i in h:
s+=1
print("no. of word of having a alphabhet :",s)
#9.using of all basic operation
a=int(input("enter a number :"))
b=int(input("enter a number :"))
print(a+b)
print(a-b)
print(a*b)
print(a**b)
print(a/b)
print(a//b)
print(a%b)
print(((a**b)+(b**2))-((a*b)**a))
#10.1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
for i in range(1,6,1):
for j in range(1,i+1,1):
print(j,end=" ")
print()
#11.1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
for i in range(1,6,1):
for j in range(1,i+1,1):
print(i,end=" ")
print()
#12.1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
for i in range(1,6,1):
for j in range(1,i+1,1):
print(i*j,end=" ")
print()
#13.1
2 8
3 12 27
4 16 36 64
5 20 45 80 125
for i in range(1,6,1):
for j in range(1,i+1,1):
print(i*(j**2),end=" ")
print()
#14. find greater commom division
import math
x=int(input("enter a no. :"))
y=int(input("enter a no. :"))
g=math.gcd(x,y)
print("greatest common division :",g)
#15. used of functions
def sum(n1,n2):
return (n1+n2)
def div(n1,n2):
return (n1/n2)
def multiply(n1,n2):
return (n1*n2)
def sub(n1,n2):
return (n1-n2)
# main program
x=int(input("enter a no. :"))
y=int(input("enter a no. :"))
print(sum(x,y))
print(multiply(x,y))
for i in range(1,101,10):
print(sum(i,5))
#16. find factorial without import math module
x=int(input("enter a no. :"))
f=1
for i in range(1,x+1,1):
f=f*i
print(f)
OR
x=int(input("enter a no. :"))
f=1
for i in range(x,1,-1):
f=f*i
print(f)
#17. find a palindrome
s=input("enter a string :")
s1=s[::-1]
if(s1==s):
print("palindrome")
else:
print("not")
#18.frequency of given no. from tuple
t=eval(input("enter a tuple :"))
n=eval(input("enter the no. whose frequency you want :"))
h=t.count(n)
print(h)
#19.reverse the order
s=input("enter a string :")
for c in range(len(s)-1,-1,-1):
print(s[c])
print()
#20. find largest no as well as position value
x=eval(input("enter a tuple :"))
l=x[0]
p=0
for i in range(len(x)):
if x[i]>l:
l=x[i]
p=i
print("largest no. :",l)
print("index value :",p)
OR
x=eval(input("enter a tuple :"))
l=max(x)
p=x.index(l)
print("largest no. :",l)
print("index value :",p)
#21. find the position of given no. from tuple
t=eval(input("enter a tuple :"))
n=int(input("enter the value whose positin you want :"))
c=t.index(n)
print("position of",n,"in tuple =",c+1)
#22. *
*
*
*
*
*
i=0
while i<6:
j=0
while j<1:
print("*",end=" ")
j=j+1
i=i+1
print()
OR
for i in range(1,7,1):
print("*",end=" ")
print()
#23.waste use of if else condition
x=int(input("enter a no :"))
y=int(input("enter a no :"))
if x<7 or x<=10 and y>8:
print("IT IS!")
else:
print("Oh No")
#24.produce a decrypted and encrypted string
def encrypt(sttr, enkey):
return enkey.join(sttr)
def decrypt(sttr, enkey):
return sttr.split(enkey)
#main
mainString=input("enter main string :")
encryptStr=input("Enter encryption key :")
enStr=encrypt(mainString,encryptStr)
deLst=decrypt(enStr,encryptStr)
deStr="".join(deLst)
print("the encrypted string is ",enStr)
print("string ater decryption is :",deStr)
#25. how to use a def function
x=5
def func(a):
b=a+1
return b
y=int(input("enter a number :"))
z=y+func(x)
print(z)
#26. to find a number is prime or composite
n=int(input("enter a no :"))
for i in range(2,n,1):
if n%i==0:
print("composite")
break
else:
print("prime")
OR
#27. find a number is prime
n=int(input("enter a number :"))
for i in range(1,n,1):
if i>1:
for num in range(2,i):
if i%num==0:
break
else:
print(i)
OR
d=int(input("enter a no :"))
s=0
for i in range(2,d,1):
if d%i==0:
s=1
if s==1:
print(d,"composite")
else:
print(d,"prime")
#28. 6=1+2+3
n=int(input("enter a number :"))
s=0
for i in range(1,n,1):
if n%i==0:
s+=i
if s==n:
print(s,"=",n)
else:
print(s,"!=",n)
#29. check whether a individual digits of given number is prime or composite
n=int(input("enter a no :"))
r=n
while r>0:
d=r%10
r=int(r/10)
s=0
for i in range(2,d,1):
if d%i==0:
s=1
if s==1:
print(d,"composite")
else:
print(d,"prime")
OR
def check_prime(digit):
if digit in (0,1):
return "neither prime nor composite"
for i in range(2,digit):
if digit % i == 0:
return "composite"
return "prime"
num=int(input("enter a number :"))
for digit in str(num):
print(f"Digit {digit} is : {check_prime(int(digit))}")
#30. *
* *
* * *
* * * *
* * * * *
* * * * * *
num=int(input("enter a number :"))
stop=int(input("enter a number :"))
while num>0:
t=num
num+=1
for j in range(1,t+1,1):
print("*",end=" ")
print()
if t==stop:
break
#31. * * * * * * * *
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
num=int(input("enter a number :"))
while num>0:
t=num
num-=1
for j in range(1,t+1,1):
print("*",end=" ")
print()