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

  What are ids and ips

Write a 2-3 page paper that fully answers the questions.

  Write a program that displays employees

Suppose the weekly hours for all employees are stored in a two-dimensional array. Each row records an employee's seven-day work hours with seven columns.

  What type information is carried by data bus and address bus

What type of information is carried by the Data Bus? The Address Bus?

  Explain components of information systems

Using the three components of information systems and the complementary assets concepts, discuss why some companies achieve better results with information systems than others.

  Create a class named commission

Create a class named Commission that includes two numeric variables: a sales figure and a commission rate. Also create two overloaded methods name computeCommission().

  Examine the following pseudocode module

Examine the following pseudocode module header and then write a statement that calls the module, passing 8 as an argument. Module showValue Integer values

  Ways to send these postcards to friends

There are k types of postcards, each with limited amount. Let there be ai copies of i-th postcard. How many ways are there to send these postcards to n friends?

  Propose three to five additional activities

Propose three to five additional activities you think should be added to a Gantt chart to help you estimate resources and durations. Write a one-page paper describing these new activities.

  The initialization program

The initialization program will start with how much you have in the cash register and in what denominations the money is in.

  Design, simulate and verify a 16-bit ripple-carry

Design, simulate and verify a 16-bit ripple-carry adder by performing the following additions/subtractions (the values of a and b are given in decimal): (i) (-10) + (100), (ii) (63) - (-127), (iii) (15) + (95), (iv) (-32) + (79), (v) (-59) + (-16)..

  Does standard unix operating system use nondiscretionary

Does the standard Unix operating system use a nondiscretionary access control? Explain your answer.

  How many block of main memory is needed-direct mapped cache

Suppose a computer using direct mapped cache has 2^32 words of main memory and a cache of 1024 blocks, where each cache block contains 32 words. How many block of main memory are there?

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