#1. program to add mul subt divide....
a=int(input("Enter a no.:"))
b=int(input("Enter a no.:"))
sum=a+b
subt=a-b
mul=a*b
div=a/b
print("The sum of given no. is:",sum)
print("The subt of given no. is:",subt)
print("The mul of given no. is:",mul)
print("The div of given no. is:",div)
The sum of given no. is: 11 The subt of given no. is: -5 The mul of given no. is: 24 The div of given no. is: 0.375
#2.Program to calculate the area and circumference of circle
r=int(input("Enter radius.:"))
area_circle=3.14*r*r
circum_circle=3.14*r*2
print("The area of the given circle is:",area_circle)
print("The circum of the given circle is:",circum_circle)
The area of the given circle is: 28.259999999999998 The circum of the given circle is: 18.84
#3.Program to calculate the area and perimeter of rect
l=int(input("Enter length:"))
b=int(input("Enter breadth:"))
area_rect=l*b
peri_rect=2*l+2*b
print("The area of the given circle is:",area_rect)
print("The area of the given circle is:",peri_rect)
The area of the given circle is: 40 The area of the given circle is: 26
# 4.Program to accept 2 number and SWAp them using 3rd variable
a=int(input("Enter 1st no.:"))
b=int(input("Enter 2nd no.:"))
temp = a
a = b
b = temp
print('The value of a after swapping: {}'.format(a))
print('The value of b after swapping: {}'.format(b))
The value of a after swapping: 8 The value of b after swapping: 5
# 5.Program to accept 2 number and SWAp them wihtout using 3rd variable
a=int(input("Enter 1st no.:"))
b=int(input("Enter 2nd no.:"))
print ("Before swapping: ")
print("Value of a : ", a, " and b : ", b)
# code to swap 'a' and 'b'
a, b = b, a
print ("After swapping: ")
print("Value of a : ", a, " and b : ", b)
Before swapping: Value of a : 4 and b : 7 After swapping: Value of a : 7 and b : 4
# 6.Program to accept marks of student of 5 subjects and calculate its sum & percentage
a=int(input("Enter your English subject marks out of 100: "))
b=int(input("Enter your Physics marks out of 100: "))
c=int(input("Enter your Chemistry marks out of 100: "))
d=int(input("Enter your Math marks out of 100: "))
e=int(input("Enter your Hindi marks out of 100: "))
#sum
sum=a+b+c+d+e
#percentage
per=sum*100/500
print('The sum of given marks is: {}'.format(sum))
print('The percentage of given marks: {}'.format(per))
The sum of given marks is: 366 The percentage of given marks: 73.2
# 7.Program to calc SI & CI
p=int(input("Enter Principal amount: "))
r=int(input("Enter rate of interest in percenatge: "))
t=int(input("Enter time : "))
S_I=p*r*t/100
a = p*(pow((1 + r / 100), t))
C_I= a - p
print('The Simple interest is: {}'.format(S_I))
print('The Compound Interest is: {}'.format(C_I))
The Simple interest is: 120.0 The Compound Interest is: 121.79999999999973
# 8.program to convert temp to celsius to fahrenheit and also fahrenheit to celsius
c=int(input("Enter temp in Centrigrade: "))
f=int(input("Enter temp in fahrenheit: "))
F=c*(9/5)+32
# fahrenheit = (celsius * 1.8) + 32
C=(f- 32) / 1.8
print('The temp {1} degree celsius in fahrenheit is: {0}'.format(F,c))
print('The temp {1} degree fahrenheit in celsius is: {0}'.format(C,f))
The temp 37 degree celsius in fahrenheit is: 98.60000000000001 The temp 100 degree fahrenheit in celsius is: 37.77777777777778
# 10. Program to calculate the years months from no. of days
d=int(input("Enter no of days no.:"))
years = d // 365
months = (d - years *365) // 30
days = (d - years * 365 - months*30)
# Displaying results
print("Years = ", years)
print("Months = ", months)
print("Days = ", days)
Years = 0 Months = 3 Days = 10
# 11. Program to check the greater number in the given two numbers
num1=int(input("Enter 1st Number: "))
num2=int(input("Enter 2nd Number: "))
if num1>num2:
print("({0}) : The 1st number is greater than ({1}) 2nd number".format(num1,num2))
else:
print("({0}) : The 1st number is smaller than ({1}) 2nd number".format(num1,num2))
(4) : The 1st number is smaller than (7) 2nd number
# 122.Program to check if you can vote or not
name=input("Enter your name: ")
age=int(input("Enter your age: "))
if age>18:
print("{0} you can vote".format(name))
else:
print("{0} you can't vote since you are too young".format(name))
dev you can vote
# 13.Program to check even and odd
num=int(input("Enter a no. : "))
if num>1:
#for i in range(2,num):
if num % 2 == 0:
print(num,"even.")
#break
else:
print(num,"odd")
else:
print(num,"Negative Value")
90 even.
#14.to check Positive & Negative
num=int(input("Enter a no. : "))
if num>0:
print(num,"Positive")
else:
print(num,"Negative Value")
9 Positive
# 15.Program to check vowel & COnsonant
alpha=input("Enter the alphabet (a-z) : ")
if alpha=='a' or alpha=='e' or alpha=='i' or alpha=='o' or alpha=='u':
print("The given alphabet ({0}) is a vowel").format(alpha)
else:
print(alpha,"The given alphabet is a COnsonant")
The given alphabet is a COnsonant
# 16.Program to check aplphabet digit or special character
alpha=input("Enter the alphabet (a-z),digit,special character : ")
if alpha=='a' or alpha=='e' or alpha=='i' or alpha=='o' or alpha=='u':
print("The given alphabet ({0}) is a vowel").format(alpha)
else:
print(alpha,"The given alphabet is a COnsonant")
The given alphabet is a COnsonant
#17. Progam to check whether its a leap year or not
def is_leap():
leap = False
if (year % 400 == 0 or year % 100 != 0 and year%4==0):
return True
else:
return leap
year=int(input())
print(is_leap())
True
#18.WAP to accept 3 numbers and find max
num1=int(input("Enter 1st Number: "))
num2=int(input("Enter 2nd Number: "))
num3=int(input("Enter 3rd Number: "))
if (num1 >= num2) and (num1 >= num3):
largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
else:
largest = num3
print("The largest no. among them is : ",largest)
The largest no. among them is : 9
#Write a program to accept three numbers and print in ascending order
# num1=int(input("Enter 1st Number: "))
# num2=int(input("Enter 2nd Number: "))
# num3=int(input("Enter 3rd Number: "))
NumList = []
Number = int(input("Please enter the Total Number of List Elements: "))
for i in range(1, Number + 1):
value = int(input("Please enter the Value of %d Element : " %i))
NumList.append(value)
NumList.sort()
print("Element After Sorting List in Ascending Order is : ", NumList)
Element After Sorting List in Ascending Order is : [3, 6, 8]
#19.Write a program to accept three numbers and print in ascending order
num1=int(input("Enter 1st Number: "))
num2=int(input("Enter 2nd Number: "))
num3=int(input("Enter 3rd Number: "))
list=[num1,num2,num3]
list.sort()
print(list)
[0, 6, 8]
# 20.Program to accept marks of student of 5 subjects and calculate its percentage & grade
a=int(input("Enter your English subject marks out of 100: "))
b=int(input("Enter your Physics marks out of 100: "))
c=int(input("Enter your Chemistry marks out of 100: "))
d=int(input("Enter your Math marks out of 100: "))
e=int(input("Enter your Hindi marks out of 100: "))
#sum
sum=a+b+c+d+e
#percentage
per=sum*100/500
if per>=90:
Grade='A'
elif per>=80:
Grade='B'
elif per>=70:
Grade='C'
elif per>=60:
Grade='D'
elif per>=40:
Grade='E'
elif per <40:
Grade='F'
print('The sum of given marks is: {}'.format(sum))
print('The percentage is ({0}) and the grade is ({1}).'.format(per,Grade))
The sum of given marks is: 368 The percentage is (73.6) and the grade is (C).
21.# 20.Program to accept marks of student of 5 subjects and calculate its percentage & grade
total_unit=float(input("Enter the total no units consumed: "))
# charge_per_unit=float(input("Enter the charges applicable on 1 unit in Rupees: "))
t=total_unit
if t<=50:
total_bill=t*0.50
elif (t>51) and (t<=150):
total_bill=(t*0.50)+(t*0.75)
elif (t>151) and (t<=250):
total_bill=(t*0.50)+(t*1.20)
elif (t>251):
total_bill=(t*1.50)
surcharge=total_bill*0.20
final_price=total_bill+surcharge
print('The total unit is ({0}) and the total bill is ({1}).'.format(total_unit,final_price))
The total unit is (12.0) and the total bill is (7.2).
# 22.
# 23.To enter month number between 1-12 and convert it in number of days
print("\n\nList of months: January, February, March, April, May, June, July, August, September, October, November, December")
#MENU
print("Choose Month NUmber\n\n")
print("Press 1 for January")
print("Press 2 for February")
print("Press 3 for March")
print(".")
print(".")
print(".")
print("Press 12 for December\n\n")
# Try exception for THE_CHOICE input
try:
the_choice = int(input())
except ValueError:
print("Invalid Input!!! Try Again\n")
# Conditions for your choice
if (the_choice == 1) or (the_choice==3) or (the_choice==5) or (the_choice==7) or (the_choice==8) or (the_choice==10) or (the_choice==12):
print('The no. of days in the selected month is', 31)
elif the_choice == 2:
print('The no of days in the selcetd month i.e. February is :' '28 or 29')
else:
print('The no of days in the selected month is : 30')
List of months: January, February, March, April, May, June, July, August, September, October, November, December Choose Month NUmber Press 1 for January Press 2 for February Press 3 for March . . . Press 12 for December The no of days in the selected month is : 30
# 24.Enter employee name & calc salary
# 25.Enter your name and print it 100 times
name=input("ENter your name: ")
for i in range(100):
print(name)
# 26 Print 1 to 100
print('Numbers from 1 to 100\n')
for i in range(1,101):
print(i,end=' ')
Numbers from 1 to 100 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
# 27 Print all even numbers from 1 to 100
print('EVEN Numbers from 1 to 100\n')
for i in range(1,101):
if i%2 == 0:
print(i,end=' ')
EVEN Numbers from 1 to 100 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100
# 28 Print all Odd numbers from 1 to 100
print('EVEN Numbers from 1 to 100\n')
for i in range(1,101):
if i%2 != 0:
print(i,end=' ')
EVEN Numbers from 1 to 100 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99
# 29.sum of all numbers form 1 to input given by user
print('Sum of Numbers from 1 to N \n')
N=int(input('Enter the number till the summation to be performed'))
sum=0
for i in range(1,N+1):
sum += i
print(sum)
Sum of Numbers from 1 to N 55
# 30 Print all Odd numbers from 1 to 100
print('Sum of Numbers from 1 to 100 \n')
sum_even=0
sum_odd=0
for i in range(1,101):
if i%2 == 0:
sum_even += i
else:
sum_odd += i
print(sum_even, 'is the sum of even numbers form 1 to 100')
print(sum_odd,' is the sum of odd umbers from 1 to 100')
Sum of Numbers from 1 to 100 2550 is the sum of even numbers form 1 to 100 2500 is the sum of odd umbers from 1 to 100
# 31. Check The given number is prime of not
print('Check whether the given number is prime or not \n')
num=int(input('Enter the number: '))
if(num>1):
for i in range(2,num):
if(num%i==0):
print("The given number ({0}) is NOT a PRIME NUMBER.".format(num))
break
else:
print("The given number ({0}) is a PRIME NUMBER.".format(num))
else:
print("You.ve given a negative Value")
Check whether the given number is prime or not The given number (10) is NOT a PRIME NUMBER.
# 32.Count and print all PRIME no.s b/w 1 to 1000#To print prime no.s from 1 to 1000
start_val = 1
end_val = 1000
count=0
for num in range(start_val, end_val+1):
if(num>1):
for i in range(2,num):
if(num%i)==0:
break
else:
print(num)
count += 1
print('The total number of prime no.s b/w 1-1000 is : {}'.format(count))
# 33.Count and print all EVEN no.s b/w 1 to 1000 that is divisible by 3
start_val = 1
end_val = 1000
count=0
for num in range(start_val,end_val+1):
if(num % 2 == 0):#for odd if(num % 2 != 0):
if(num%3==0):
print(num, end = ",")
count += 1
print('\nThe total number of prime no.s b/w 1-1000 that is divisible by 3 is : {}'.format(count))
6,12,18,24,30,36,42,48,54,60,66,72,78,84,90,96,102,108,114,120,126,132,138,144,150,156,162,168,174,180,186,192,198,204,210,216,222,228,234,240,246,252,258,264,270,276,282,288,294,300,306,312,318,324,330,336,342,348,354,360,366,372,378,384,390,396,402,408,414,420,426,432,438,444,450,456,462,468,474,480,486,492,498,504,510,516,522,528,534,540,546,552,558,564,570,576,582,588,594,600,606,612,618,624,630,636,642,648,654,660,666,672,678,684,690,696,702,708,714,720,726,732,738,744,750,756,762,768,774,780,786,792,798,804,810,816,822,828,834,840,846,852,858,864,870,876,882,888,894,900,906,912,918,924,930,936,942,948,954,960,966,972,978,984,990,996, The total number of prime no.s b/w 1-1000 that is divisible by 3 is : 166
#34.Calculate The factorial of a number given by the user
#35. PRint all lep yer and Century leap year till today..
print('Leap year List from 1 to today\n')
for i in range(1,2023):
if (i % 400 == 0 or i % 100 != 0 and i%4==0):
print(i ,end=",")
Leap year List from 1 to today 4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,104,108,112,116,120,124,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192,196,204,208,212,216,220,224,228,232,236,240,244,248,252,256,260,264,268,272,276,280,284,288,292,296,304,308,312,316,320,324,328,332,336,340,344,348,352,356,360,364,368,372,376,380,384,388,392,396,400,404,408,412,416,420,424,428,432,436,440,444,448,452,456,460,464,468,472,476,480,484,488,492,496,504,508,512,516,520,524,528,532,536,540,544,548,552,556,560,564,568,572,576,580,584,588,592,596,604,608,612,616,620,624,628,632,636,640,644,648,652,656,660,664,668,672,676,680,684,688,692,696,704,708,712,716,720,724,728,732,736,740,744,748,752,756,760,764,768,772,776,780,784,788,792,796,800,804,808,812,816,820,824,828,832,836,840,844,848,852,856,860,864,868,872,876,880,884,888,892,896,904,908,912,916,920,924,928,932,936,940,944,948,952,956,960,964,968,972,976,980,984,988,992,996,1004,1008,1012,1016,1020,1024,1028,1032,1036,1040,1044,1048,1052,1056,1060,1064,1068,1072,1076,1080,1084,1088,1092,1096,1104,1108,1112,1116,1120,1124,1128,1132,1136,1140,1144,1148,1152,1156,1160,1164,1168,1172,1176,1180,1184,1188,1192,1196,1200,1204,1208,1212,1216,1220,1224,1228,1232,1236,1240,1244,1248,1252,1256,1260,1264,1268,1272,1276,1280,1284,1288,1292,1296,1304,1308,1312,1316,1320,1324,1328,1332,1336,1340,1344,1348,1352,1356,1360,1364,1368,1372,1376,1380,1384,1388,1392,1396,1404,1408,1412,1416,1420,1424,1428,1432,1436,1440,1444,1448,1452,1456,1460,1464,1468,1472,1476,1480,1484,1488,1492,1496,1504,1508,1512,1516,1520,1524,1528,1532,1536,1540,1544,1548,1552,1556,1560,1564,1568,1572,1576,1580,1584,1588,1592,1596,1600,1604,1608,1612,1616,1620,1624,1628,1632,1636,1640,1644,1648,1652,1656,1660,1664,1668,1672,1676,1680,1684,1688,1692,1696,1704,1708,1712,1716,1720,1724,1728,1732,1736,1740,1744,1748,1752,1756,1760,1764,1768,1772,1776,1780,1784,1788,1792,1796,1804,1808,1812,1816,1820,1824,1828,1832,1836,1840,1844,1848,1852,1856,1860,1864,1868,1872,1876,1880,1884,1888,1892,1896,1904,1908,1912,1916,1920,1924,1928,1932,1936,1940,1944,1948,1952,1956,1960,1964,1968,1972,1976,1980,1984,1988,1992,1996,2000,2004,2008,2012,2016,2020,
# 36.WAP to accept a number and print sum of its digit (n=123,sum=1+2+3)
NumList = []
Number = int(input("Please enter the Total Number of List Elements: "))
for i in range(1, Number + 1):
value = int(input("Please enter the Value of %d Element : " %i))
NumList.append(value)
NumList.sort() # to sort in ascending order
print(NumList)
Sum = sum(NumList) #sum() func in python
print('The Sum of the given digits is : ',Sum)
[2, 5, 5, 8] The Sum of the given digits is : {0} 20
# 37.WAP to Check whether the given no. is Armstrong No. or not (n=153,sum=1^3+2^3+3^3)
num = 153
sum=0
temp=num
while temp > 0:
digit =temp%10 #Finding the sum of cube of each digit
sum += digit **3
temp //=10
if num == sum:
print(num,"is an Armstrong Number.")
else:
print(num,"is not an Armstrong Number.")
# This program only work for 3 digit numbers....
153 is an Armstrong Number.
# 37.WAP to Check whether the given no. is Armstrong No. or not (n=153,sum=1^3+2^3+3^3)
num = 1634
order = len(str(num))
sum=0
temp=num
while temp > 0:
digit =temp%10 #Finding the sum of cube of each digit
sum += digit **order
temp //=10
if num == sum:
print(num,"is an Armstrong Number.")
else:
print(num,"is not an Armstrong Number.")
# This program only work for 3 digit numbers....
1634 is an Armstrong Number.
# 38.PRogram to print Armostrong NUmber from 1 to 1000.
lower=1
upper=1000
for num in range (lower, upper + 1):
order=len(str(num))
sum=0
temp=num
while temp>0:
digit =temp % 10
sum += digit ** order
temp //= 10
if num==sum:
print(num,end=',')
1,2,3,4,5,6,7,8,9,153,370,371,407,
# 39.WAP to accept a number and reverse it (n=123,321)
NumList = []
Number = int(input("Please enter the Total Number of List Elements: "))
for i in range(1, Number + 1):
value = int(input("Please enter the Value of %d Element : " %i))
NumList.append(value)
NumList.sort(reverse=True) # to sort in descending order
print('The Ouput of the given digits after reversing is : {}'.format(NumList))
print(NumList)
The Ouput of the given digits after reversing is : [42, 6, 5, 4, 4, 4, 4, 3, 3, 3, 2, 2, 1] [42, 6, 5, 4, 4, 4, 4, 3, 3, 3, 2, 2, 1]
#40.WAP to accept a No. & check whether it is palindrome or not
s=str(313)
if(s == s[::-1]):
print("The given number is Palindrome")
else:
print("The given number is Not a Palindrome")
The given number is Palindrome
#40.WAP to accept a No. & check whether it is palindrome or not
s=str(313)
if(s == s[::-1]):
print("The given number is Palindrome")
else:
print("The given number is Not a Palindrome")
The given number is Palindrome
#41.WAP tp accept a number and find max & min digit amongst them.
NumList = []
Number = int(input("Please enter the Total Number of List Elements: "))
for i in range(1, Number + 1):
value = int(input("Please enter the Value of %d Element : " %i))
NumList.append(value)
# print(max(NumList))
# print(min(NumList))
print('The largest of the given digits is ({0}) and smallest is ({1}).'.format(max(NumList),min(NumList)))
print(NumList)
The largest of the given digits is (8) and smallest is (4). [8, 6, 4]
#41.WAP tp accept a number and find max & min digit amongst them.
NumList = [1,2,3]
# if(s == s[::-1]):
# print("The given number is Palindrome")
# else:
# print("The given number is Not a Palindrome")
sum=(max(NumList))+(min(NumList))
sub=(max(NumList))-(min(NumList))
# print(max(NumList))
# print(min(NumList))
print('The largest of the given digits is ({0}) and smallest is ({1}).'.format(max(NumList),min(NumList)))
print('And their sum =',sum)
for i in NumList:
if(i%2==0):
print("The SUM of the max & min is a EVEN number")
print('SO their SUBTRACTION is : ',sub)
else:
print("The SUM of the max & min is a ODD number")
print('SO their ADDITION is is : ',sum)
The largest of the given digits is (3) and smallest is (1). And their sum = 4 The SUM of the max & min is a ODD number SO their ADDITION is is : 4 The SUM of the max & min is a EVEN number SO their SUBTRACTION is : 2 The SUM of the max & min is a ODD number SO their ADDITION is is : 4
#41.WAP tp accept a number and find max & min digit amongst them.
NumList = [1,2,2]
sum=(max(NumList))+(min(NumList))
# print(max(NumList))
# print(min(NumList))
print('The largest of the given digits is ({0}) and smallest is ({1}).'.format(max(NumList),min(NumList)))
print('And their sum =',sum)
if(sum%2==0):
print("The SUM of the max & min is a EVEN number")
print('SO their SUBTRACTION is : ',sub)
elif(sum%2!=0):
print("The SUM of the max & min is a ODD number")
print('SO their ADDITION is : ',sum)
The largest of the given digits is (2) and smallest is (1). And their sum = 3 The SUM of the max & min is a ODD number SO their ADDITION is : 3
#42.WAP t0 accept a number and find max & min digit amongst them.
NumList = [2,2,6]
if(min(NumList)%2==0 and max(NumList)%2==0):
print('sum = ',(max(NumList))+(min(NumList)))
elif(min(NumList)%2!=0 and min(NumList)%2==0):
print('subtraction = ',(max(NumList))-(min(NumList)))
else:
print('product is : ',(max(NumList))*(min(NumList)))
sum = 8
# 43. WAP to accept a number and calculate sum of its factors
num=25
num_list=[]
print("The factors of the given number is : ")
for i in range(1, num+1):
if num%i == 0:
print(i,end=',')
num_list.append(i)
# print(num_list)
print('\nAnd the sum of its factors is',sum(num_list),'.')
#44.WAP to accept a number and print in word..
from num2words import num2words
# Most common usage.
print(num2words(11098))
# can also specify this for -th format
print(num2words(11098, to='ordinal'))
eleven thousand and ninety-eight eleven thousand and ninety-eighth
#45.
#46. Program to remove zeroes from a given digits
# a list of numbers as input from a user
input_string = '2 0 3 0 5 6 0'#input the string separated by space,
user_list = input_string.split()
print("\n")
# print list
print('list: ', user_list)
# convert each item to int type
for i in range(len(user_list)):
user_list[i] = int(user_list[i])
val = 0
try:
while True:
user_list.remove(val)
except ValueError:
pass
print(user_list) # prints [1, 1, 1, 1]
list: ['2', '0', '3', '0', '5', '6', '0'] [2, 3, 5, 6]
#47
#48
#49
#50(i) Sum of natural numbers up to N
num = 1000
if num < 0:
print("Enter a positive number")
else:
sum = 0
# use while loop to iterate until zero
while(num > 0):
sum += num
num -= 1
print("The sum is", sum)
The sum is 500500
#50(i) Sum of natural numbers up to N which is divisible by 2
import math
num = 1000
if num < 0:
print("Enter a positive number")
else:
sum = 0
# use while loop to iterate until zero
while(num > 0):
for i in num():
if i%2==0:
sum += num
num -= 1
print("The sum is", sum)
#54.WAP to accept a program to accept a string and count vowel,consonant & word in it.
n='devendra singh'
countvowel=0
countconso=0
for i in n:
if (i=='a' or i=='e' or i=='i' or i=='o' or i=='u'):
countvowel=countvowel+1
else:
countconso=countconso+1
print(countvowel)
print(countconso)
4 10
#(54,55).WAP to accept a program to accept a string and count Vowel,Consonant & Word in it.
def countCharacterType(str):
vowels = 0
consonant = 0
specialChar = 0
digit = 0
for i in range(0, len(str)):
#to convert to str value
ch = str[i]
if ( (ch >= 'a' and ch <= 'z') or
(ch >= 'A' and ch <= 'Z') ):
# To handle upper case letters
ch = ch.lower()
if (ch == 'a' or ch == 'e' or ch == 'i'or ch == 'o' or ch == 'u'):
vowels += 1
else:
consonant += 1
elif (ch >= '0' and ch <= '9'):
digit += 1
else:
specialChar += 1
print("WOrds: ", (res))
print("Vowels:", vowels)
print("Consonant:", consonant)
print("Digit:", digit)
print("Special Character:", specialChar)
str = "Dev is going@"
res = len(str.split())
#to avoid spaces to be counted as special characters
str=str.replace(' ','')
countCharacterType(str)
WOrds: 3 Vowels: 4 Consonant: 6 Digit: 0 Special Character: 1
#56.WAP aceept a string and reverse it
str = "Hello World"[::-1]
print(str)
dlroW olleH
#56.WAP aceept a string and reverse it.(USing Function)
def my_function(x):
return x[::-1]
mytxt = my_function("I wonder how this text looks like backwards")
print(mytxt)
sdrawkcab ekil skool txet siht woh rednow I
#57.WAP to accept a string and check given string is palindrome or not.
str_input="mom"
list_str_input=str_input.split()
c=0
for i in list_str_input:
if i==i[::-1]:
print('IS a Palindrome')
print('Palindrome word =',i)
c += 1
else:
print('Not a Palindrome')
print("NO. of palindrome word =",c)
IS a Palindrome Palindrome word = mom NO. of palindrome word = 1
#57.WAP to accept a string and check given string is palindrome or not.(using function)
#Define a function
def isPalindrome(string):
if (string== string[::-1]):
return("The string is a palindrome.")
else:
return("The string is not a palindrome.")
#Enter input string
string=input("Enter string:")
print(isPalindrome(string))
The string is not a palindrome.
#58.WAP to accept a string and count & print all palindrome word in given string.
# Exampe-welcome to mom and dad world-
str_input="welcome to mom and dad world"
list_str_input=str_input.split()
c=0
for i in list_str_input:
if i==i[::-1]:
print(i)
c += 1
print("NO. of palindrome word =",c)
mom dad NO. of palindrome word = 2
# 59.Wap to a String and count and print all world which have no is vowel
# Exampk=-cat fly in the sky- ans= fly, sky
str_input="cat fly in the sky"
list_str_input=str_input.split()
c=0
for i in list_str_input:
ch = str[i]
if (ch == 'a' or ch == 'e' or ch == 'i'or ch == 'o' or ch == 'u'):
print(i)
c += 1
print("NO. of palindrome word =",c)
#60.WAP to accept a string and remove all vowels
par = "zyz how are you"
result=str()
count = 0
for ch in par:
if (ch == 'a' or ch == 'e' or ch == 'i'or ch == 'o' or ch == 'u'):
pass
else:
result = result + ch
count += 1
print(result)
zyz hw r y
#61. Wap to a string and print two substring of vowel and consonant
# Exampe="united" ans:• sl="uie" s2="ntd"
par = "united"
result=str()
vowel=str()
count = 0
for ch in par:
if (ch == 'a' or ch == 'e' or ch == 'i'or ch == 'o' or ch == 'u'):
vowel += ch
else:
result = result + ch
count += 1
print('The S1 string with vowels is :',vowel)
print('The S2 string with Conso is :',result)
The S1 string with vowels is : uie The S2 string with Conso is : ntd