Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8066431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:59:35+00:00 2026-06-05T11:59:35+00:00

I was working through CoderByte ‘Python’ questions. Time is of essence, so the code

  • 0

I was working through CoderByte ‘Python’ questions. Time is of essence, so the code may not be really readable but pretty straight forward. I will be interested in your approach. My code works for some words but testing with ‘sentence’ is giving me a different result, debugging as we speak. Please comment on my thinking!

Question :

Have the function LetterChanges(str) take the str parameter being passed and modify it using the following algorithm. Replace every letter in the string with the letter following it in the alphabet (ie. c becomes d, z becomes a). Then capitalize every vowel in this new string (a, e, i, o, u) and finally return this modified string. Use the Parameter Testing feature in the box below to test your code with different arguments. Do not modify the function name within the code. Do not put any code outside of the function and use the return keyword to return your answer from within the function.

My code :

def LetterChanges(str): 
    a = map(chr, range(97, 123))
    b = ['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']
    b.remove('a')
    b.append('a')
    c = dict(zip(a,b))
    v = ['a', 'e', 'i', 'o', 'u']

    k = str
    for i in range(len(str)):
        if str[i] in a:
            k = k.replace(str[i], c[str[i]])

    l = k
    for i in range(len(k)):
        if k[i] in v:
            l = l.replace(k[i], k[i].upper())

    print l

# this call is needed to test your function
# keep this when you submit your code
LetterChanges(str)

Output :

zddzst -> AEEAUU {wrong}!
sentence -> UfOUfOdf {wrong}!
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T11:59:37+00:00Added an answer on June 5, 2026 at 11:59 am

    I would use str.translate() for this, it might look something like this:

    import string
    
    def LetterChanges(s):
        orig = string.letters
        new = string.ascii_lowercase[1:] + 'a' + string.ascii_uppercase[1:] + 'A'
        for vowel in 'aeiou':
            new = new.replace(vowel, vowel.upper())
    
        table = string.maketrans(orig, new)
        return s.translate(table)
    

    Example:

    >>> LetterChanges('sentence')
    'tfOUfOdf'
    

    For more efficiency, I would move the creation of table outside of the function so that it is only calculated once, instead of on each function call. Alternatively just hard code the end values for orig and new, like this:

    import string
    
    def LetterChanges(s):
        t = string.maketrans('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
                             'bcdEfghIjklmnOpqrstUvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZA')
        return s.translate(t)
    

    edit: Here is a version that should work with coderbytes restrictions:

    def LetterChanges(s):
        orig = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
        new = 'bcdEfghIjklmnOpqrstUvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZA'
        result = ''
        for c in s:
            if c in orig:
                c = new[orig.index(c)]
            result += c
        return result
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working through a sample in Chapter 3 of Programming in Scala, the following code
Working through a zend tutorial & get this message, & not sure where to
So I'm working through the code in this tutorial which has a small button
I am working through a problem which I was able to solve, all but
Working through Pro ASP.NET MVC book and I got the following code snippet that
I am just working through some examples from my text book, writing the code
I am working through the Agile Web Development with Rails book but I have
I'm working through K & R to learn programming. Going well so far, but
I am working through an MVVM tutorial, and I have the following code, written
I am working through a code sample, and I just want to hear some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.