The built in python string functions

Assignment Help Basic Computer Science
Reference no: EM13341138

You will be creating different functions! For each assignment, you will create a single function.
Template

# Your code header goes here, as always
# This function takes a single letter and a string,
# and returns the number of times the letter occurs in
# the string. (The function will not work if the first
# argument is not a single letter).

def count(letter, myString):

# This function takes in a single list as input, and
# returns the same list sorted.

def sort(myList):


# This function checks to see whether the argument,
# a string, is or is not a palindrome. It will return
# True for palindromes and false otherwise.

def isPalindrome(myString):



# Main will not be graded for correctness; rather,
# we want to see you test these three functions. This
# is for your own sanity as well--you should go through this
# process with every function you write. Each function should
# get called 3 or 4 times with different input, and you should
# print the return value to make sure it is correct.
#
# Included is an example to get you started.

def main():
print("Counting numbers of a's in aardvark:")
print(count("a", "aardvark"))
# Should print 3
You may write more functions than we give you, but you must create the ones listed below.

letterCount(letter, myString) This function should take a single letter, and then a string. It should return the number of times letter occurs in myString. So the call letterCount('h', 'hello') should return 1, and the call letterCount('a', 'aardvark') should return 3. Do not use any of the built in python string functions.

sortList(myList) This function should take myList and return myList sorted. If you are struggling with this, use your code from part 4 of the last homework. If you already have code that puts a number into an already sorted list, with an extra loop sorting shouldn't be that hard. So calling sortList([4, 5, 3, 1]) should return [1, 3, 4, 5], and sortList([8, 10, 1, 2]) should return [1, 2, 8, 10].

isPalindrome(myString) Returns True if myString is a palindrome (the same forward as it is backward) and False otherwise. myString will be a single word. For example, isPalindrome("tacocat") should return True, isPalindrome("anna") should return True, and isPalindrome("DanTheMan") should return False.

main() Main should be used by you to test your program. The main you should submit should show 3 to 4 examples of your function working. So for the isPalindrome, you could print out the result of calling isPalindrome on each of the three strings we gave you in the example, along with one or two examples in which your function works. main() does not need to do things in any particular order or format. Simply call each function 3 or 4 times with different input and print the output. We will be looking at it by hand to make sure you tested your programs.

Reference no: EM13341138

Questions Cloud

What is a security risk assessment : What is a Security Risk Assessment?
Spam is email still a useful information service : Given all the problems with spam is email still a useful information service? Research other networked services available on Linux servers and compare them with email. (500 words)
Use a triangle to indicate the challenges and bus processes : Use a triangle to indicate the challenges and bus processes changes
Necessarily memorize to the best of the machine abilities : If a researcher uses computer models for studying the memorization capabilities of the human mind, do the programs developed for the machine necessarily memorize to the best of the machine's abilities? Explain.
The built in python string functions : letterCount(letter, myString) This function should take a single letter, and then a string. It should return the number of times letter occurs in myString. So the call letterCount('h', 'hello') should return 1, and the call letterCount('a', 'aa..
Use an open-addressed hashing table of size m : 1)Suppose that we use an open-addressed hashing table of size m to store n ? m / 2 items. Assuming uniform hashing, show that for i = 1, 2, ..., n, the probability is at most 2?k that the i-th insertion requires strictly more than k probes.
Provide analysis on the difference between batch : Provide analysis on the difference between batch, visual basic, and powershell scripts then analyze when you would use each scripts and for what purpose. I.E. Batch for reception, powershell and VBScript for Administioration.
How long is your commute to work : Survey Questions - When writing survey questions it is very important to be careful how you word your questions. For example, if someone is asked, "How long is your commute to work," you might get answers that say how long it takes someone to ..
Staples : Staples

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

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