Best writers. Best papers. Let professionals take care of your academic papers

Order a similar paper and get 15% discount on your first order with us
Use the following coupon "FIRST15"
ORDER NOW

Problem 1#Recall in Unit 3 you wrote a function that would count the#number of

Problem 1#Recall in Unit 3 you wrote a function that would count the#number of

words in a string using loops. Now that you know

#something about string methods, though, let’s do that again

#using a different approach.

#

#rite a function called “num_words” that accepts a string

#as an argument and returns the number of words in the

#string. You can assume all words are separated by a space,

#and that the string has at least one word. You do not need

#to worry about punctuation.

#

#For example:

#

# num_words(“Veni, Vidi, Vici.”) -> 3

def num_words (string):

   aList = string.split()

   string.split(string)

   return string

#Below are some lines of code that will test your function.

#You can change the value of the variable(s) to test your

#function with different inputs.

#

#If your function works correctly, this will originally

#print: 3, 2, 1, each on their own line.

print(num_words(“Vini, Vidi, Vici.”))

print(num_words(“Hello, world!”))

print(num_words(“HeyDavidwhyaren’ttherespacesinthissentence”))

Problem 2

#rite a function called string_length. string_length should

#have one parameter, a string. It should return a 2-tuple:

#the first item in the 2-tuple should be the string itself,

#and the second item should be the length of the string as

#given by the len() function.

#Below are some lines of code that will test your function.

#You can change the value of the variable(s) to test your

#function with different inputs.

#

#If your function works correctly, this will originally

#print:

print(string_length(“Hello, world!”))

print(string_length(“CS1301”))

print(string_length(“Some people pronounce it ‘toople’. Others pronounce it ‘tuhple’. Either is correct.”))

 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"