Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python P4.3 Write programs that read a line of input as a string and print a. On

ID: 3881136 • Letter: P

Question

Python P4.3 Write programs that read a line of input as a string and print
a. Only the uppercase letters in the string.
b. Every second letter of the string. c. The string, with all vowels replaced by an underscore.
d. The number of digits in the string.
e. The positions of all vowels in the string.
Python P4.3 Write programs that read a line of input as a string and print
a. Only the uppercase letters in the string.
b. Every second letter of the string. c. The string, with all vowels replaced by an underscore.
d. The number of digits in the string.
e. The positions of all vowels in the string.
P4.3 Write programs that read a line of input as a string and print
a. Only the uppercase letters in the string.
b. Every second letter of the string. c. The string, with all vowels replaced by an underscore.
d. The number of digits in the string.
e. The positions of all vowels in the string. P4.3 Write programs that read a line of input as a string and print
a. Only the uppercase letters in the string.
b. Every second letter of the string. c. The string, with all vowels replaced by an underscore.
d. The number of digits in the string.
e. The positions of all vowels in the string.

Explanation / Answer

a = input("Enter a string:")
print("string entered: ",a)
#a
#printing
#Only the uppercase letters in the string.
print("printing Only the uppercase letters in the string.")
for i in a:
if(ord(i)>=65 and ord(i)<=90):
print(i,end='')
print(" ")
#b
#Every second letter of the string.
n =a
l = n.split(' ')
print('printing Every second letter of the string')
for i in l:
if(len(i)>1):
print(i[1])

#c
#The string, with all vowels replaced by an underscore.
print("printing vowels replaced by underscore:")
for i in a:
if(i=='u' or i=='U' or i=='o' or i=='O' or i=='i' or i=='I' or i=='e' or i=='E' or i=='a' or i=='A'):
print('_',end='')
else:
print(i,end='')
print(" ")
#d
#The number of digits in the string.
print("The number of digits in the string: ",end='')
c=0
for i in a:
if(ord(i)>=48 and ord(i)<=57):
c+=1#counting numbers
print(c)
#e
#The positions of all vowels in the string.
print("The positions of all vowels in the string: ");
cc=0
for i in a:
if(i=='u' or i=='U' or i=='o' or i=='O' or i=='i' or i=='I' or i=='e' or i=='E' or i=='a' or i=='A'):
print(cc,' ',end='')
cc+=1
print(" ")

output:

>>> ================================ RESTART ================================
>>>
Enter a string:Hello World1
string entered: Hello World1
printing Only the uppercase letters in the string.
HW

printing Every second letter of the string
e
o
printing vowels replaced by underscore:
H_ll_ W_rld1

The number of digits in the string: 1
The positions of all vowels in the string:
1 4 7

>>>