Source code
Q10. Write a program to accept a number from the user and check whether it is
prime or not
source code
num=int(input('enter number here'))
a=2
b=3
if num%2==0 or num%3==0:
print('number is not prime')
else:
print('prime')
output
num=int(input('enter number here'))
a=2
b=3
if num%2==0 or num%3==0:
print('number is not prime')
else:
print('prime')
Q12 Write a program to print following pattern-:
**
***
****
*****
Source code
for i in range (0,5):
for j in range (0,i+1):
print('*',end=' ')
print()
output
**
***
****
*****
Source code
for i in range(70,76):
for j in range(76,i-1,-1):
print(chr(j),end=' ')
print()
output
FGHIJ
FGHI
FGH
FG
F
Source code
Source code
st=input('enter string here')
tc=0
ta=0
td=0
ts=0
for i in st:
tc+=1
if ord(i)>64 and ord(i)<91 and ord(i)>96 and ord(i)<123:
ta+=1
for i in '0123456789':
td+=1
else :
ts+=1
print('total characters',tc)
print('total alphabets',ta)
print('total digits',td)
print('total special',ts)
output
enter string herehello
total characters 5
total alphabets 5
total digits 0
total special 0
Source code
st=input('enter string here')
for i in range(len(st)):
print(st[i],'-',st.count(st[i])
output
enter string hereheya
h-1
e-1
y-1
a–1
Source code
the=0
st=input('enter string here')
l=st.split()
for i in l:
if len(i)==3 and i[0] in 'Tt' and i[1] in 'hH' and i[2] in 'eE':
the+=1
print ('total the in the string is-',the)
output
enter string herethe mouse
total the in the string is- 1
souce code
the=0
st=input('enter string here')
l=st.split()
for i in l:
if i[0] in 'aeiouAEIOU' and i[len(i)-1] not in 'aeiouAEIOU':
the+=1
print('total words',the)
output
enter string herehello
total words 0
INDEX