Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

# 1. Count digits # Parity is the math term describing whether a number is even or odd. # By definition, 0 has even parity.

# 1. Count digits # Parity is the math term describing whether a number is even or odd. # By definition, 0 has even parity. # remember to check the test cases below for examples

def count_digits(s, parity): """count_digits. This function must return the number of digits found in the string parameter of the given parity.

Parameters: s (str): A string of any composition. parity (str): A string that's either "Even", "Odd", or "Either". Either will count all digits found.

Returns: n (int): An integer """ return

# 2. oddish_or_evenish # A number is oddish if the sum of all of its digits is odd, and a number is evenish if the sum of all of its digits is even. # remember to check the test cases below for examples

def oddish_or_evenish(num): """oddish_or_evenish. This function must return the word "oddish" if the number is oddish or the word "evenish" if the number is evenish

Parameters: num (int): A positive integer.

Returns: s (str): A new string. """ return

# B. reverse_string # remember to check the test cases below for examples def reverse_string(s1): """reverse_string. This function must return the string in reversed order. Python doesn't have a string.reverse() method so you'll need to create it.

Parameters: s1 (str): A string of any composition.

Returns: s2 (str): A new string. """ return

def calculate_speeding_advantage(limit, average_speed, distance): """calculate_speeding_advantage. This function must return the time saved by exceeding the speed limit for a given distance.

Parameters: limit (int): A positive int average_speed (float): A positive float > 0 in km per hr. distance (int): A positive distance in km >= average_speed.

Returns: time_saved (float): A new float representing the number of minutes you will save """ return

# Provided simple test() function used in main() to print # what each function returns vs. what it's supposed to return.

def test(got, expected): if got == expected: prefix = ' OK ' else: prefix = ' X ' print('%s got: %s; expected: %s' % (prefix, repr(got), repr(expected)))

# Provided main() calls the above functions with interesting inputs, # using test() to check if each result is correct or not. def main(): print('count_digits') test(count_digits("hello world", "Even"), 0) test(count_digits("hello world", "Odd"), 0) test(count_digits("Christmas falls on December 25 each year in Canada.", "Odd"), 1) test(count_digits("Christmas falls on December 25 each year in Canada.", "Either"), 2) test(count_digits( "The address of UTM is 3359 Mississauga Rd, Mississauga, ON L5L 1C6", "Even"), 1) test(count_digits( "The address of UTM is 3359 Mississauga Rd, Mississauga, ON L5L 1C6", "Odd"), 6) test(count_digits( "The address of UTM is 3359 Mississauga Rd, Mississauga, ON L5L 1C6", "Either"), 7) test(count_digits("1234567890", "Even"), 5) test(count_digits("1234567890", "Odd"), 5) test(count_digits("1234567890", "Either"), 10)

print print('oddish_or_evenish') test(oddish_or_evenish(43), "Oddish") test(oddish_or_evenish(373), "Oddish") test(oddish_or_evenish(41), "Oddish") test(oddish_or_evenish(4433), "Evenish") test(oddish_or_evenish(1001), "Evenish")

print print('reverse_string') test(reverse_string("University of Toronto, Mississauga"), "aguassissiM ,otnoroT fo ytisrevinU") test(reverse_string("pjzfoY9sHv"), "vHs9Yofzjp") test(reverse_string("The professor's name is Michael Nixon"), "noxiN leahciM si eman s'rosseforp ehT") test(reverse_string("My Social Insurance Number is 373 296 086"), "680 692 373 si rebmuN ecnarusnI laicoS yM")

# Standard boilerplate to call the main() function. if __name__ == '__main__': main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server T-SQL Recipes

Authors: David Dye, Jason Brimhall

4th Edition

1484200616, 9781484200612

More Books

Students also viewed these Databases questions

Question

what you would do to address the situation.

Answered: 1 week ago