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

  Deriving logging information for chinese wall model

In the example of deriving required logging information for the Chinese Wall model, it is stated that the time must be logged.Why? Explain.

  Design the class doctortype

Design the class doctorType, inherited from the class personType, with an additional data member to store doctors speciality. Add appropriate constructors and member functions to initialize, access, and manipulate the data members.

  Issue -internet changed political interactions globally

Write a 500 word essay based on the issue of ways in which the internet has changed political interactions globally. These might involve political activity in several specific countries,

  Develop a program to play lottery

Suppose you want to develop a program to play lottery. The program randomly generates a Lottery of a two-digit number, prompts the user to enter a two-digit number, and determines whether the user wins according to the following rule.

  Write method called swappairs accepts string as parameters

Write a method called swapPairs that accepts a String as a parameter

  Write a regular expression that selects lines

These letters may appear in uppercase as well. For this exercise you must surround your solution with double quotes .

  Create a jframe that uses borderlayout

Create a JFrame that uses BorderLayout. Place a JButton in the center region. Each time the user clicks the JButton, change the background color in one of the other regions. Save the file as JColorFrame.java.

  What max number of dimensions a c++ multidimensional array

What is the MAX number of Dimensions for a C++ multidimensional array ?

  What is probability that one of students will beliving

What is the probability that one of the students will beliving on campus given that he orshe is from out of state?

  Briefly describe what the notion

Briefly describe what the notion of "normal operation" means to an executing computer program

  Dynamic programming

Please provide with a detailed answer using DYNAMIC PROGRAMMING

  Create a web archive file and attach to this assignment

Name your JSP FormPost4 and name the application Week7. Create a Web archive file and attach to this assignment.

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