Question

Function 2: In this function assume that the first parameter is a string that contains characters...

Function 2: In this function assume that the first parameter is a string that contains characters in A-Z and a-z only. The only functions you are allowed to use are range(), len(), chr(), ord().

YOU CAN NOT USE .upper or .lower, can only use the functions said above.
• Examples:

◦ func2("GeorgeMason") → "GeorgeMason"

◦ func2("GeorgeMason", "upper", 2, 3) → "GeORgeMason"

◦ func2("GeorgeMason", "upper", 5) → "GeorgEMASON"

◦ func2("GeorgeMason", "lower") → "georgemason"

◦ func2("GeorgeMason", s=8, c="upper") → "GeorgeMaSON"

◦ func2("GeorgeMason", "lower", e=0) → "georgeMason"

0 0
Add a comment Improve this question Transcribed image text
Answer #1

def func2(str1):

    print('func2("GeorgeMason") →',str1)

    str2=""

    for i in range(0,len(str1)):

       if(i==2):

           p=ord(str1[i])

           str2=str2+chr(p-32)

       elif(i==3):

             p=ord(str1[i])

             str2=str2+chr(p-32)

       else:

             str2= str2+str1[i]

    print('func2("GeorgeMason", "upper", 2, 3) →',str2)

    str2=""

    for i in range(0,len(str1)):

       if(i==5 or i>5):

           p=ord(str1[i])

           if(chr(p-32)>='A' and chr(p-32)<='Z'):

                str2=str2+chr(p-32)

           else:

                str2=str2+str1[i]

           

       else:

             str2= str2+str1[i]

    print( 'func2("GeorgeMason", "upper", 5) → ',str2)

    str2=""

    for i in range(0,len(str1)):

        p=ord(str1[i])

        if(p>=97 and p<=122):

            str2=str2+str1[i]

        else:

            p=ord(str1[i])

            str2=str2+chr(p+32)

    print('func2("GeorgeMason", "lower") →',str2)

    str2=""

    for i in range(0,len(str1)):

       if(i==8 or i>8):

           p=ord(str1[i])

           if(chr(p-32)>='A' and chr(p-32)<='Z'):

                str2=str2+chr(p-32)

           else:

                str2=str2+str1[i]

           

       else:

             str2= str2+str1[i]

    print('func2("GeorgeMason", s=8, c="upper") →',str2)

    str2=""

    for i in range(0,len(str1)):

        p=ord(str1[i])

        if(p==71):

            str2=str2+chr(p+32)

        else:

            str2=str2+str1[i]

    

    print('func2("GeorgeMason", "lower", e=0) →',str2)

    

str1="GeorgeMason"

list1=['A','B','C','D','E','F','G','H','I','J','K','L',

       'M','N','O','P','Q','R','S','T','U','V','W','X',

       'Y','Z','a','b','c','d','e','f','g','h','i','j',

       'k','l','m','n','o','p','q','r','s','t','u','v',

       'w','x''y','z']

count=0

for i in str1:

    if i in list1:

            #print('hi')

            count=count+1

    

if(count==len(str1)):

    func2(str1)

func2 ("GeorgeMason")- GeorgeMason func2 ("GeorgeMason", "upper", 2, 3) - GeORgeMason func2 ("GeorgeMason", "upper", 5)GeorgEMASON func2 ("GeorgeMason", "lower") - georgemason func2 ("GeorgeMa son", s-8, c-"upper")-GeorgeMaSON func2( "GeorgeMason", "lower", e#0)-georgeMason

Add a comment
Know the answer?
Add Answer to:
Function 2: In this function assume that the first parameter is a string that contains characters...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • python Implement function get_contact(contacts, name) that returns a string. The contacts and the name parameter are...

    python Implement function get_contact(contacts, name) that returns a string. The contacts and the name parameter are both type string. This function checks for the name string in the contacts string and returns that person's contact information. If the person is not found, the function returns, "name not in contact". Assume input is always valid. Assume the same name is not repeated in contacts. [You may use split(), range(), len() ONLY and no other built-in function or method] Examples: contacts =...

  • project-8a Write a function named count_letters that takes as a parameter a string and returns a...

    project-8a Write a function named count_letters that takes as a parameter a string and returns a dictionary that tabulates how many of each letter is in that string. The string can contain characters other than letters, but only the letters should be counted. The string could even be the empty string. Lower-case and upper-case versions of a letter should be part of the same count. The keys of the dictionary should be the upper-case letters. If a letter does not...

  • 10. replaceSubstring Function Write a function named replaceSubstring. The function should accept three C-string or string...

    10. replaceSubstring Function Write a function named replaceSubstring. The function should accept three C-string or string object arguments. Let's call them string1, string2, and string3. It should search string for all occurrences of string2. When it finds an occurrence of Programming Challenges string2, it should replace it with string. For example, suppose the three arguments have the following values: stringt: "the dog jumped over the fence" string 2 "the" string3: "that" With these three arguments, the function would return a...

  • python function will Return True if string x contains 3 vowels in a row, in consecutive...

    python function will Return True if string x contains 3 vowels in a row, in consecutive locations, false otherwise. assuming that 'vowels' refer to the following lowercase lttrs: a,e,i,o,u programs fails partially, only allowed to use float, str, int, appen, split, strip, len, range def vowels_three(x): for i in range (o, len(x), 2): if x[i] not in ('a,e,i,o,u'): return False return True

  • 2) Hashing functions can be applied to string of characters. For example "amigo" and "annex" can...

    2) Hashing functions can be applied to string of characters. For example "amigo" and "annex" can be assigned hashing value 0, "bike" and "bureaucrat" can be assigned 1, "zebra" can be assigned value 25. So in order to find the hashing value of a word, we find the hashing value of the first letter (ht(a)=0, ht(b)=1, ht(c)=2,….,ht(z)=25). So in this case it is necessary 26 buckets. a) Give an example of another hashing function on string of characters, and determine...

  • Requriements: Submit only the files requested Print all floats to 2 decimal points unless stated otherwise...

    Requriements: Submit only the files requested Print all floats to 2 decimal points unless stated otherwise Descripition : For this problem you will be implementing a Caesarin Cipher. A Caesarin Cipher takes a string and a shift amount and shift the characters in the string by the shift amount. Specifications: Only characters should be ciphered If a character is shifted beyond the end of the aphabet it should wrap back around For example if the letter 'y' is shifted 3...

  • Python please Write a function print_back_upper() that accepts a string my_str as an argument and displays...

    Python please Write a function print_back_upper() that accepts a string my_str as an argument and displays the string backwards and in uppercase, all in one line (Note: Create any necessary variables) For example: if my_str = "Python" then, your output should display as follows: NOHTYP (Hint: You can use for loop navigating up to range of len of string-1, -1, -1 and use reverse() and upper() functions to create and display the string backwards in uppercase)

  • #Write a function called check_formula. The check_formula #function should take as input one parameter, a string....

    #Write a function called check_formula. The check_formula #function should take as input one parameter, a string. It #should return True if the string holds a correctly #formatted arithmetic integer formula according to the rules #below, or False if it does not. # #For this problem, here are the rules that define a #correctly-formatted arithmetic string: # # - The only characters in the string should be digits or the five arithmetic operators: +, -, *, /, and =. Any other...

  • Define the is_a_valid_date() function which is passed a string as a parameter. The function returns a...

    Define the is_a_valid_date() function which is passed a string as a parameter. The function returns a boolean indicating whether the parameter string is a valid date or not. The first two lines of the function are: month_names = ["January", "February", "March","April", "May", "June", "July", "August", "September", days_in_month = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31) where month_names is a list of valid month names, and days_in_month is a list which contains the maximum day number...

  • Define the is_a_valid_date() function which is passed a string as a parameter. The function returns a...

    Define the is_a_valid_date() function which is passed a string as a parameter. The function returns a boolean indicating whether the parameter string is a valid date or not. The first two lines of the function are: month_names = ["January", "February", "March", "April", "May", "June", "July", "August", "September", days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] where month_names is a list of valid month names, and days_in_month is a list which contains the maximum day...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT