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

  • Home
  • SEARCH
  • 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 6218995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:42:14+00:00 2026-05-24T07:42:14+00:00

import string ## This part of the code initializes the program by recieving inputs

  • 0
import string

## This part of the code initializes the program by recieving inputs and saving
## them as strings.
## It also currently works!

intext = str.lower(raw_input("Please input the text you are going to use. "))
##print intext
instring = str.lower(raw_input("Please input your string. "))
##print instring
inlengthminus = int(raw_input("Please input the number of words you would like before the matched word. ONLY PUT AN INTEGER HERE!"))
inlengthplus = int(raw_input("Please input the number of words you would like after the matched word. ONLY PUT AN INTEGER HERE!"))
## This part of the code splits the text into searchable lists.
## It only works when the cases match, which is why the search lists
## convert the text to lowercase.

searchtext=str.split(intext)
##print searchtext
searchstring=list(instring+1)
##print searchstring

## This is the actual search process.
## It works, mostly.

length = len(searchtext)
stringlength = len(searchstring)
##print stringlength

x=0
for a in range(0,length):
    print a
    print searchstring[x]
    print x
    if searchstring[x] in searchtext[a]:
        if (a-inlengthminus)<0:
            print "You almost caused an error, please pick a number of words before your matched word that won't call text that doesn't exist."
            break
        else:
            print searchtext[a-inlengthminus:a+inlengthplus+1]    
            x+=1
    else:
        pass

I don’t know how to stop this program from calling a value for searchstring[x] that is greater than the length of searchstring. Is there a way to stop x from causing this overflow error?

  • 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-05-24T07:42:15+00:00Added an answer on May 24, 2026 at 7:42 am

    Replace

    x+=1
    

    With

    x = (x + 1) % len(searchstring)
    

    The modulus operator does division and returns the remainder. So x from 0 up to the length of searchstring, the modulus does nothing (returns itself). If x == the length of searchstring, it “resets” to 0, because there is no remainder when dividing.

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

Sidebar

Related Questions

This is good: import string string.capwords("proper name") Out: 'Proper Name' This is not so
Which CPU information this code is trying to retrieve. This code is part of
I am writing a standalone code for Sending mail from java. In this program
It seems like there should be a simpler way than: import string s =
My users will import through cut and paste a large string that will contain
Given a string with a module name, how do you import everything in the
How do I extract a double value from a string using regex. import re
I'm copying code from one part of our application (an applet) to inside the
This is sort of a two part question. I'm building a flash image viewer
I'm learning to use Java's Pattern and Matcher, and this is an example code

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.