# XI TERM 1 9 TO 15 RECORD PROGRAMS
9. Accept a sentence and print Number of Uppercase characters, lowercase
characters, spaces,
digits and special characters.
sent=input("Enter a sentence : ")
low=up=dig=sp=sc=0
for ch in sent:
if ch.isalpha():
if ch.islower():
low+=1
elif ch.isupper():
up+=1
elif ch.isspace():
sp+=1
elif ch.isdigit():
dig+=1
else:
sc+=1
print("\nNo.of lowercase characters : ",low)
print("\nNo.of uppercase characters : ",up)
print("\nNo.of spaces : ",sp)
print("\nNo.of digits : ",dig)
print("\nNo.of Special char : ",sc)
OUTPUT:
Enter a sentence : This is a class of 50 students.
No.of lowercase characters : 21
No.of uppercase characters : 1
No.of spaces : 6
No.of digits : 2
No.of Special char : 1
10. Write a program that does the following.
i) Accept two inputs: one integer and one string
ii) Extract all the digits, in the order they occur from the given string,
add the given integer input and the digits extracted from the string.
iii) If no digits occur in the given string, set the extracted digit to 0.
Output 1:
Enter integer no: 12
Enter the string : a4b5c6
given number = 12
given string a4b5c6
sum = 12 + 456 = 468
Output 2:
Enter integer no: 20
Enter the string : hello
given number = 20 given string = hello sum = 20 +0= 20
num=int(input("Enter integer no: "))
st = input("Enter any string (with alphabets and digits) : ")
x=''
for i in st:
if i.isdigit():
x+=i
if x=='':
x='0'
print("The sum of the number", num," and the digits",x," in the string is :
",num+int(x))
OUTPUT
Enter an integer : 90
Enter any string with alphabets and digits : dfgh5fv1g
The sum of the number 90 and the digits 51 in the string is : 141
Enter an integer : 44
Enter any string with alphabets and digits : fghj
The sum of the number 44 and the digits in the string is : 44
11. Write a program that reads a line of strings and print all the
palindrome words from the line.
Eg. S=Ajay has a RacecAr. He is a level 1 racer.
Palindrome words: RacecAr level
=input('enter string')
print('given string ',s)
a=''
for i in s.split():
if len(i)==1:
continue
if i[-1]==".":
i=i[0:len(i)-1]
if i.lower() == i[::-1].lower():
a+=i+' '
if a=='':
print('No palindrome words')
else:
print('Palindrome words are :',a)
OUTPUT
enter stringAjay has a RacecAr. He is a level 1 racer.
given string Ajay has a RacecAr. He is a level 1 racer.
Palindrome words are : RacecAr level
12. Write a program to input a string S1. Input two substrings S2 and S3 existing
in Sl and a replacemnent string S4. Replace-the range of strings-starting- from S2-
till end of S3- with S4.
Eg: Given string S= ´one two three one two three
Substring S1= two
Substring S2 = th'
Substring S3 = five'
Output: one fiveree one two three
s=input("Enter a sentence : ")
s1=input("Enter substring S1 : ")
s2=input("Enter substring S2 : ")
s3=input("Enter substring S3 : ")
a=s.find(s1)
b=s.index(s2)
ns=s[:a]+s3+s[b+len(s2):]
print('given string = ',s)
print('new string = ',ns)
OUTPUT
Enter a sentence : one two three one two three
Enter substring S1 : two
Enter substring S2 : th
Enter substring S3 : five
given string = one two three one two three
new string = one fiveree one two three
Enter a sentence : where there is will there is a way
Enter substring S1 : there
Enter substring S2 : is
Enter substring S3 : exists
given string = where there is will there is a way
new string = where exists will there is a way
13. Write a program that takes a string with multiple words and then capitalizes
the first letter of each word and reverses all three letter words.
Eg: Given String = I have a car in red colour'
New string = I Have A raC In deRColour
s=input('enter string')
print('given string ',s)
print('modified string ',end='')
s1=s.title()
for i in s1.split():
if len(i)==3:
print(i[::-1],end=' ')
else:
print(i,end=' ')
OUTPUT
enter stringI have a car in red colour
given string I have a car in red colour
modified string I Have A raC In deR Colour
14. Write a program that reads a line and prints the longest word, its length and
print the same word without vowels.
Eg: Given String = 'Python offers many methods for string manipulation'
Output l
Longest substring: manipulation
Its Length: 12
Output 2
Longest substring without vowels : mnpltn
s=input('enter string')
print('given string ',s)
max=0
maxs=''
for i in s.split():
if len(i)>max:
max=len(i)
maxs=i
print('Longest word : ',maxs)
print('longest word without vowels :',end=' ')
for i in maxs:
if i in 'aeiou':
continue
else:
print(i,end='')
OUTPUT
enter stringPython offers many methods for string manipulation
given string Python offers many methods for string manipulation
Longest word : manipulation
longest word without vowels : mnpltn
15. Write a program to read N phone numbers with 10 digits and 2 dashes in the
format 999-999-9999.
Print all the valid phone numbers.
Eg: Given phone numbers
044-225-2461
12-234-1235
044-223-1234
Output:
Valid phone numbers
044-225-2461
044-223-1234
n=int(input('enter the limit'))
s=''
for i in range(n):
pno=input('enter phone number with dashes')
if pno[:3].isdigit() and pno[3]=='-' and pno[4:7].isdigit() and pno[7]=='-' and
pno[8:].isdigit():
s+=pno+' '
if s=='':
print('no valid phone numbers')
else:
print('valid phone numbers are:')
for i in s.split():
print(i)
OUTPUT
enter the limit3
enter phone number with dashes044-225-2461
enter phone number with dashes12-234-1235
enter phone number with dashes044-223-1234
valid phone numbers are:
044-225-2461
044-223-1234