Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

here is a test code import pythonBasics2 # main() is already set up to call the functions # we want to test with a few

image text in transcribed

here is a test code

import pythonBasics2 # main() is already set up to call the functions # we want to test with a few different inputs, # printing 'OK' when each function is correct. # the simple provided test() function used in main() to print # what each function returns vs. what it's supposed to return. def test(got, expected): prefix = ' OK ' if got == expected else ' X ' print ('%s got: %s expected: %s' % (prefix, repr(got), repr(expected))) def main(): # set which functions to test check_count_threes = True check_longest_consecutive_repeating_char = False check_is_palindrome = False if check_count_threes: print('Testing count_threes:') test(pythonBasics2.count_threes(0), 0) test(pythonBasics2.count_threes(2), 0) test(pythonBasics2.count_threes(3), 1) test(pythonBasics2.count_threes(6), 2) test(pythonBasics2.count_threes(24), 8) if check_longest_consecutive_repeating_char: print("---------------------------------------------------------") print('longest_consecutive_repeating_charater') test(pythonBasics2.longest_consecutive_repeating_char('aaa'), 'a') test(pythonBasics2.longest_consecutive_repeating_char('abba'), 'b') test(pythonBasics2.longest_consecutive_repeating_char('caaddda'), 'd') test(pythonBasics2.longest_consecutive_repeating_char('aaaffftttt'), 't') test(pythonBasics2.longest_consecutive_repeating_char('aaababbacccca'), 'c') test(pythonBasics2.longest_consecutive_repeating_char('ddabab'), 'd') test(pythonBasics2.longest_consecutive_repeating_char('caac'), 'a') if check_is_palindrome: print("-------------------------------------------------------") print('Testing is_palindrome') test(pythonBasics2.is_palindrome("Hello"), False) test(pythonBasics2.is_palindrome("civic"), True) test(pythonBasics2.is_palindrome("Civic"), True) test(pythonBasics2.is_palindrome("Racecar"), True) test(pythonBasics2.is_palindrome("Dont nod"), True) test(pythonBasics2.is_palindrome("was it a cat I saw"), True) test(pythonBasics2.is_palindrome("It was not a cat"), False) if __name__ == '__main__': main() 
A E# Python Activity # # Fill in the code for the functions below. # The starter code for each function includes a 'return # which is just a placeholder for your code. Make sure to add what is going to be returned. # Part A. count_threes # Define a function count_threes(n) that takes an int and # returns the number of multiples of 3 in the range from # to n (including n). Eidef count_threes(n): # YOUR CODE HERE return # Part B. Longest_consecutive_repeating_char # Define a function Longest_consecutive_repeating_char(s) that takes D# a string s and returns the character that has the longest consecutive repeat. Eder Longest consecutive-repeating-char(s): # YOUR CODE HERE e return www # Part C. is_palindrome # Define a function is_palindrome (s) that takes a strings # and returns whether or not that string is a palindrome. # A palindrome is a string that reads the same backwards and # forwards. Treat capital letters the same as Lowercase one's # and ignore spaces (i.e. case insensitive). Edef is-palindrome (s): # YOUR CODE HERE

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

More Books