Construct a python function named finder that takes two

Assignment Help Python Programming
Reference no: EM132354775

Question

Construct a Python function named finder that takes two string parameters, needle and haystack. Your function should find the first (i.e. left-most) occurrence of needle in haystack and return its position as an int, where 0 means the first character in the string, and so on. If needle does not occur in haystack, your program should return -1.

Examples:

finder ('a' , 'bananas ') # 1

finder ('na' , 'bananas ') # 2

finder ('nas' , 'bananas ') # 4

finder ('banana ' , 'bananas ') # 0

finder ('nanner ' , 'bananas ') # -1

For the purposes of this problem, you must implement your solution as a loop (either while or for, your choice). Specifically, the index, find, and other functions on string objects are prohibited. You are, however, permitted to use the indexing and slicing operators (that is, s[n] and s[n:m]).

Reference no: EM132354775

Questions Cloud

Create one-year advertising budget and plan : Identify its primary target market. Create a one-year advertising budget and plan that incorporates the use of various advertising media and publicity.
Calculate monthly payments : Tim borrowed $25,000 at a rate of 8.64% compounded semi-annually (j2). Calculate his monthly payments if he amortizes his payments over 5 years.
What rate would you actually be paying here : The interest rate quotation in this example requires the borrower to pay 5 points to the lender up front and repay the loan later with 9 percent interest
What rate would you actually be paying here : A point on a loan is simply 1 percent (one percentage point) of the loan amount. Quotes similar to this one are common with home mortgages.
Construct a python function named finder that takes two : Construct a Python function named finder that takes two string parameters, needle and haystack. Your function should find the first.
Health law and ethic : What is the organizational structure of the company or agency with which you work? Which ethical principles and theories apply to the scenario you selected?
Achieve the breakeven point : Fixed manufacturing costs total $1280 per month, while fixed selling and administrative costs total 2,420. How many phones must be sold to achieve the breakeven
Estimated total costs for a production level : Use the high low method to find the estimated total costs for a production level of 32,000 unite?
What is kathy incremental profit : Kathy is trying to decide whether or not to attend college during the next 12 week session. She has the following options.

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd