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 8727503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:26:45+00:00 2026-06-13T08:26:45+00:00

I am new to Python and having a problem with the modulo. Here is

  • 0

I am new to Python and having a problem with the modulo.

Here is the code:

for i in range(ord('a'), ord('z')+1):
    print chr(((i+2) % 97) + 97 )

The exptected result is cdef...a. However I am not getting the desired module behavior of wrapping around once we get to z.

  • 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-13T08:26:46+00:00Added an answer on June 13, 2026 at 8:26 am

    Because 97 isn’t what you want to be wrapping at – you want to be wrapping at ord('z') = 122, and then adding the value of ord('a') (97).

    The full math you really need to be doing is to shift into an offset, and then back to the set. For instance…

    for i in range(ord('z') - ord('a') + 1): # equivalent to range(26); i.e. 0-25
        print chr(((i+2) % 26) + ord('a')) # results in 2+97 'c', 3+97 'd', etc.
    

    The reason your existing code isn’t working is because your i+2 will always be greater than 97 (since your i starts at ord('a') which is 97, and goes up from there), so the % 97 is effectively just - 97, and thus your print line is effectively this:

    print chr(((i+2) - 97) + 97 )
    

    which reduces to…

    print chr((i+2) - 97 + 97)
    

    which is obviously just print chr(i+2).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a performance problem in my code. I'm a little new to Python
Hello I am a new user to Python and I am having problem doing
I'm very new to Python development, and am having a problem with one of
I'm pretty new to Python, so hopefully the problem I'm having has a simple
I am new to python and I am having a problem. I want to
The problem I am having at this point in time (being new to Python)
I'm new in python and I'm having many troubles in using global instruction. Here
I'm new to python and I'm having a problem that I'm not able to
I'm new to Python and I'm having a problem viewing error messages: I have
I'm a new Python programmer who is having a little trouble using 'self' in

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.