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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:03:26+00:00 2026-06-04T13:03:26+00:00

I’m following a python website for my schoolwork. It’s really neat, it gives you

  • 0

I’m following a python website for my schoolwork. It’s really neat, it gives you tasks to complete and compiles the code in the browser. Anyway, I came to a challenge that I’m not really sure how to go about.

One of the questions was:

The same substring may occur several times inside the same string: for example “assesses” has the substring “sses” 2 times, and
“trans-Panamanian banana” has the substring “an” 6 times. Write a
program that takes two lines of input, we call the first needle and
the second haystack. Print the number of times that needle occurs as a
substring of haystack.

I’m not too sure how I should start this, I know I have to compare the two strings but how? I used the count method, but it didn’t recognize the second occurrence of sses in assesses.

My second question is one I solved but I cheated a little.

The question was:

Write a program that takes a single input line of the form «number1»+«number2», where both of these represent positive integers,
and outputs the sum of the two numbers. For example on input 5+12 the
output should be 17.

I used the eval() method and it worked, I just think that this wasn’t what the grader had in mind for this.

Any insight would be greatly appreciated.

EDIT: Second question was solved.

  • 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-04T13:03:28+00:00Added an answer on June 4, 2026 at 1:03 pm

    For the first question, str.count() does not find overlapping matches, as you noticed. Instead, use str.find() and advance your starting index after each time you find a match, until the result is -1, for example:

    >>> 'assesses'.find('sses', 0)    # first look at the start of the string
    1
    >>> 'assesses'.find('sses', 2)    # now look at previous index + 1
    4
    >>> 'assesses'.find('sses', 5)    # now look at previous index + 1
    -1
    

    Since there were two results before we got -1, we know that there are two locations to find 'sses' in 'assesses'.

    For you second question, you will need to split() the string on '+', which will give you a list of two strings. Call int() on each of them, and then add them together.

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

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have just tried to save a simple *.rtf file with some websites and
Basically, what I'm trying to create is a page of div tags, each has

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.