22: assert function_exercises.is_vowel('c') == False 23: assert function_exercises.is_vowel('a') == True 24: 25: from function_exercises import is_vowel 26: 27: assert is_vowel('c') == False 28: assert is_vowel('a') == True 29: 30: from function_exercises import is_vowel as is_this_a_vowel 31: 32: assert is_this_a_vowel('c') == False 33: assert is_this_a_vowel('a') == True 34: 35: import function_exercises 36: 37: assert function_exercises.is_consonant('a') == False 38: assert function_exercises.is_consonant('c') == True 39: 40: from function_exercises import is_consonant 41: 42: assert is_consonant('a') == False 43: assert is_consonant('c') == True 44: 45: from function_exercises import is_consonant as is_this_a_consonant 46: 47: assert is_this_a_consonant('a') == False 48: assert is_this_a_consonant('c') == True 49: 50: # 2. For the following exercises, read about and use the itertools module from the standard library to help you solve the problem. 51: 52: # How many different ways can you combine the letters from "abc" with the numbers 1, 2, and 3?
# Import and test 3 of the functions from your functions exercise file. # Import each function in a different way: # import the module and refer to the function with the . syntax # use from to import the function directly # use from and give the function a different name import function_exercises as fn from function_exercises import is_consonant from function_exercises import handle_commas as hc fn.is_vowel("a") fn.is_consonant("n") hc("1,000") # How many different ways can you combine the letters # from "abc" with the numbers 1, 2, and 3? # combos = itertools.permutations(list_1, len(list_2)) # print(combos) # unique = [] # for comb in combos: # zipped = zip(comb, list_2) # unique.append(list(zipped)) list_1 = ["a","b","c"] list_2 = [1,2,3] import itertools list_3 = list(itertools.product(list_1,list_2)) print(list_3) print(len(list_3)) # How many different ways can you combine
# import the module and refer to the function with the . syntax import function_exercises function_exercises.is_two(2) function_exercises.is_vowel("f") function_exercises.is_consonant("g") # use from to import the function directly from function_exercises import is_two, is_vowel, is_consonant is_two(4) is_vowel("a") is_consonant("z") # use from and give the function a different name from function_exercises import is_two as num, is_vowel as vowel, is_consonant as cons num(2) vowel("a") cons("a") # itertools module import itertools as it # How many different ways can you combine the letters from "abc" with the numbers 1, 2, and 3? len(list(it.product("abc","123", repeat=1)))
# 1)Import each function in a different way: # import the module and refer to the function with the . syntax import function_exercises function_exercises.is_two(3) function_exercises.is_vowel("b") function_exercises.is_consonant("e") # use from to import the function directly from function_exercises import is_two from function_exercises import is_vowel from function_exercises import is_consonant is_vowel("b") # use from and give the function a different name import function_exercises as fe fe.is_two(9) fe.is_vowel("i") fe.is_consonant("h") # How many different ways can you combine the letters from "abc" with the numbers 1, 2, and 3? from itertools import product letters = "abc"
assert function_exercises.is_vowel('c') == False assert function_exercises.is_vowel('a') == True from function_exercises import is_vowel assert is_vowel('c') == False assert is_vowel('a') == True from function_exercises import is_vowel as is_this_a_vowel assert is_this_a_vowel('c') == False assert is_this_a_vowel('a') == True import function_exercises assert function_exercises.is_consonant('a') == False assert function_exercises.is_consonant('c') == True from function_exercises import is_consonant assert is_consonant('a') == False assert is_consonant('c') == True from function_exercises import is_consonant as is_this_a_consonant assert is_this_a_consonant('a') == False assert is_this_a_consonant('c') == True # 2. For the following exercises, read about and use the itertools module from the standard library to help you solve the problem. # How many different ways can you combine the letters from "abc" with the numbers 1, 2, and 3?