Question

In: Computer Science

PYTHON Define a function named variousChanges(...) which receives one string (origst) (with letters, digits or special...

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

Solutions

Expert Solution

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:)


Related Solutions

In Python Create a function called ????. The function receives a "string" that represents a year...
In Python Create a function called ????. The function receives a "string" that represents a year (the variable with this "String" will be called uve) and a list containing "strings" representing bank accounts (call this list ????). • Each account is represented by 8 characters. The format of each account number is "** - ** - **", where the asterisks are replaced by numeric characters. o For example, “59-04-23”. • The two central characters of the "string" of each account...
In PYTHON: Write a function that receives an encrypted string and decrypts it as follows. The...
In PYTHON: Write a function that receives an encrypted string and decrypts it as follows. The decryption does not change the lowercase letters ‘e’, ‘w’, and ‘l’ (lowercase L). For any other character, we change it to a number using ord(). We then take the number to a power of 19, and then find the remainder after diving by 201. Finally, we take the character corresponding to the number we obtained (using chr()). For example, assume that we receive the...
Python program. Write a function called cleanLowerWord that receives a string as a parameter and returns...
Python program. Write a function called cleanLowerWord that receives a string as a parameter and returns a new string that is a copy of the parameter where all the lowercase letters are kept as such, uppercase letters are converted to lowercase, and everything else is deleted. For example, the function call cleanLowerWord("Hello, User 15!") should return the string "hellouser". For this, you can start by copying the following functions discussed in class into your file: # Checks if ch is...
Python: Write a function that receives a one dimensional array of integers and returns a Python...
Python: Write a function that receives a one dimensional array of integers and returns a Python tuple with two values - minimum and maximum values in the input array. You may assume that the input array will contain only integers and will have at least one element. You do not need to check for those conditions. Restrictions: No built-in Python data structures are allowed (lists, dictionaries etc). OK to use a Python tuple to store and return the result. Below...
Python program.  from random import . Write a function called cleanLowerWord that receives a string as a...
Python program.  from random import . Write a function called cleanLowerWord that receives a string as a parameter and returns a new string that is a copy of the parameter where all the lowercase letters are kept as such, uppercase letters are converted to lowercase, and everything else is deleted. For example, the function call cleanLowerWord("Hello, User 15!") should return the string "hellouser". For this, you can start by copying the following functions discussed in class into your file: # Checks...
Write a Python module that must satisfy the following- Define a function named rinsert. This function...
Write a Python module that must satisfy the following- Define a function named rinsert. This function will accept two arguments, the first a list of items to be sorted and the second an integer value in the range 0 to the length of the list, minus 1. This function shall insert the element corresponding to the second parameter into the presumably sorted list from position 0 to one less than the second parameter’s index.   Define a function named rinsort. This...
C++ Please Define a function named "isAscending" that accepts a string as an input parameter and...
C++ Please Define a function named "isAscending" that accepts a string as an input parameter and returns "true" if all the characters included in the string are ordered in ascending order of their ASCII codes or the input string is a null string, and returns "false" otherwise. For example, if the string "ABXab" is passed to the function, it returns "true" because the ASCII code of 'B' is greater than 'A', 'X' is greater than 'B', 'a' is greater than...
Define a function digits_stars(...) which receives as input one digit (that is, an integer number greater...
Define a function digits_stars(...) which receives as input one digit (that is, an integer number greater or equal than 0 and less or equal than 9). The function should return a string. The string will have , alternating, a digit and a "*" symbol, starting with the digit 0, then a star, then the digit 1, then a star, and so on, alternating until reaching the input digit and one star symbol to end the string. As an example, the...
Write a Python program: The function is named validity(). It receives 2 floating point parameters, min...
Write a Python program: The function is named validity(). It receives 2 floating point parameters, min and max, from the program that invoked it. The function asks the user to enter a float number. Using a while loop it checks whether the number is valid (between min and max, inclusive). If not valid, the while loop uses this statement to prompt for a new number: num = float (input (" Enter a number that is at least :"+ str(min) +...
Creates a function called pick. The function receives a "string" representing one year (the variable with...
Creates a function called pick. The function receives a "string" representing one year (the variable with this "string" will be called uve) and a list containing "strings" representing bank accounts (call this bera list). <br> • Each account is represented by 8 characters. The format of each account number is "**-**-**", where asterisks are replaced by numeric characters. o For example, "59-04-23". • The two central characters of the "string" for each account represent the year the account was created....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT