In: Computer Science
PYTHON Define a function named variousChanges(...) which receives one string (origst) (with letters, digits or special characters), possibly empty, and returns a new string containing the following.
a) in those positions where the original string has an
even digit, the corresponding character in the new
(returned) string should have the string digit
'0'
b) in those positions where the original string has a vowel
letter (upper or lower case), the new (returned) string
should have the letter 'V'. Note that the
vowels are : 'a', 'e', 'i', 'o', 'u'
c) any other position in the new (returned) string
should have a star ('*')
AND
d) at the end of the new string, there should be a number attached,
which is the number of upper case letters in the
original string.
For example,
variousChanges("A>e>X34S") should return the string
"V*V***0*3" because:
'A' (in position 0) and 'e' (in position 2) are vowels --- so
the new string has a 'V' in those positions
'4' (in position 6) is an even digit --- so the new string has a
'0' in that position
all other positions have '*' in the new string
'A' , 'X' and 'S' are three upper case letters in the original
string --- so the new string has a 3 at the end
hello,
providing you the function for your requirement:-(i will also provide the snapshot of the function to reduce indentation error)
code starts here:-
def variousChanges(origst):
count=0
x=''
for i in origst:
if(i.isdigit()):
if(int(i)%2==0):
x=x+'0'
else:
x=x+'*'
elif i in
'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM':
if(i.isupper()):
count=count+1
if i in 'aeiouAEIOU':
x=x+'V'
else:
x=x+'*'
else:
x=x+'*'
x=x+str(count)
return x
code ends here:-
snapshot of code:-
sample output for test run as :-
.
output:-
i hope i was able to solve your problem to a greater extent, please feel free to comment your queries, Please consider my efforts and upvote my solution.
Thanku:)