# Your functions exercise are not currently in a file with a # name that can be easily imported. Copy your functions exercise # file and name the copy functions_exercises.py. # 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 f print(f.accepts_string('hello')) from function_exercises import calculate_tip print(calculate_tip(45,.18)) from function_exercises import apply_discount as disc print (disc(3456,.07)) # How many different ways can you combine the letters from "abc" with the # numbers 1, 2, and 3? from itertools import permutations print(list(permutations(["a","b","c", 1,2,3]))) print(len(list(permutations(["a","b","c", 1,2,3]))))
##### Import Exercises ##### # 1. Import and test 3 of the functions from your functions exercise file. # Import each function in a different way: # a. Run an interactive python session and import the module. # Call the is_vowel function using the . syntax. # b. Create a file named import_exericses.py. # Within this file, use from to import the calculate_tip function directly. # Call this function with values you choose and print the result. from function_exercises import calculate_tip print('------------------------------------------------------------') print(' ~~ Exercise 1 ~~ ') print(calculate_tip(.15, 100)) # c. Create a jupyter notebook named import_exercises.ipynb. # Use from to import the get_letter_grade function and give it an alias. # Test this function in your notebook. # Make sure your code that tests the function imports is run from the same directory that your functions exercise file is in. # Read about and use the itertools module from the python standard library to help you solve the following problems: import itertools as it # How many different ways can you combine the letters from "abc" with the numbers 1, 2, and 3? print('------------------------------------------------------------') print(' ~~ Exercise 2 ~~ ') countlist = (list(it.product('abc123'))) print(f'there are {len(countlist)} ways to combine abc and 123') # How many different combinations are there of 2 letters from "abcd"? abcdlist = list(it.combinations('abcd', 2))
from function_exercises import calculate_tip print (" bill total = 100 tip .20. the amount of tip :", calculate_tip(.20,100))
# -- Your functions exercise are not currently in a file with a name that can be easily imported. Copy your functions exercise file and name the copy functions_exercises.py. # # -- Import each function in a different way: # # -- import the module and refer to the function with the . syntax # In[1]: import function_exercises # In[2]: function_exercises.calculate_tip(0.2, 50) # -- use from to import the function directly # In[3]: from function_exercises import apply_discount # In[4]: apply_discount(4697, 0.3)
import function_exercises import itertools import json #1 b x = function_exercises.calculate_tip(.15, 100) print(x) #1c in jupyter notebook #2 x = len(list(itertools.product('abc', '123'))) print('{} number of combinations'.format(x)) y = len(list(itertools.combinations('abcd', 2))) print('{} number of combinations'.format(y)) z = len(list(itertools.permutations('abcd', 2))) print('{} number of combinations'.format(z)) #3 dataset = json.load( open( "/Users/xaviercarter/codeup_data_science/python-exercises/profiles.json" )) #total number of users w = len(dataset) print(f'{w} users total') #total number of active users
# 1. Import and test 3 of the functions from your functions exercise file. # Import each function in a different way: # 1a. Run an interactive python session and import the module. Call the is_vowel # function using the . syntax. import function_exercises as fn print(fn.is_vowel('b')) # 1b. Create a file named import_exericses.py. Within this file, use from to import the # calculate_tip function directly. Call this function with values you choose and print the result. from function_exercises import calculate_tip print(calculate_tip(0.20, 100)) # 1c. Create a jupyter notebook named import_exercises.ipynb. Use from to import the get_letter_grade # function and give it an alias. Test this function in your notebook. from function_exercises import get_letter_grade as grd print(grd(85)) # 2. Read about and use the itertools module from the python standard library to help you solve the following problems: # How many different ways can you combine the letters from "abc" with the numbers 1, 2, and 3? # import itertools # print(itertools.product('abc', '123')) # or