예제 #1
0
#!/usr/bin/env python
# coding: utf-8

# In[35]:

# import the module and refer to the function with the . syntax

# import function_exercises
import function_exercises
from function_exercises import is_vowel

# import is_vowel to determine if string is a vowel
function_exercises.is_vowel('a')

# In[36]:

# use from to import the function directly

# using from to import handle_commas with no alias
from function_exercises import handle_commas

# using handle_commas to remove comma from string
handle_commas('3,000.25')

# In[37]:

# use from and give the function a different name

# using from to import capital_consonant with alias 'capcon'
from function_exercises import capital_consonant as capcon

#     1. 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
function_exercises.is_two(2)

import function_exercises as fe
fe.is_vowel('a')

from function_exercises import is_consonant as c
c('a')

#     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?
#           - How many different ways can you combine two of the letters from "abcd"?

#  - How many different ways can you combine the letters from "abc" with the numbers 1, 2, and 3?

from itertools import *
abc = list(product('abc', '123'))
print(abc)

# - How many different ways can you combine two of the letters from "abcd"?

from itertools import * # import itertools
예제 #3
0
import function_exercises as fe

print('')
print('BEGGINING OF IMPORT EXERCISES')
print('with imported functions exercise above for function recalls')
print('Exercise 1(a)')

# ^ importing our function exercises and aliasing it as fe for easier referencing

print(fe.is_vowel('u'))
print(fe.is_vowel('x'))

print('----------------------------------------')

print('Exercise 1(b)')

# using from to import calculate tip from my function exercises
from function_exercises import calculate_tip as ct
# calling the function with it aliased name from above with the correct parameters
print(ct(.20, 120))

print('----------------------------------------')

print('Exercise 1(c)')

# using from to import and aliasing function name as GG
from function_exercises import get_letter_grade as gg
# calling the function with the correct parameters and alias
print(gg(74))

print('----------------------------------------')
예제 #4
0
# IMPORT EXERCISES

# 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'))
예제 #5
0
  7: assert function_exercises.is_two(2) == True
  8: assert function_exercises.is_two('two') == False
  9: 
 10: from function_exercises import is_two
 11: 
 12: assert is_two(2) == True
 13: assert is_two('two') == False
 14: 
 15: from function_exercises import is_two as is_it_two
 16: 
 17: assert is_it_two(2) == True
 18: assert is_it_two('two') == False
 19: 
 20: import function_exercises
 21: 
 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
예제 #6
0
# use from to import the function directly
# use from and give the function a different name


# In[3]:


import function_exercises
function_exercises.is_two(2)


# In[4]:


from function_exercises import is_vowel
is_vowel("a")


# In[5]:


from function_exercises import is_consonant as ic
ic("a")


# In[6]:


# 2. For the following exercises, 
# read about and use the itertools module from the standard library to help you solve the problem. 
# 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 
예제 #8
0
# 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"
예제 #9
0
    Import each function in a different way:


"""

"""
    import the module and refer to the function with the . syntax
    
>>> import function_exercises
>>> function_exercises.is_vowel('A')
True
"""

import function_exercises
print(function_exercises.is_vowel('A'))

"""
    use from to import the function directly

>>> from function_exercises import twelveto24
>>> twelveto24('12:01am')
'0:01'
"""

from function_exercises import twelveto24
twelveto24('12:01am')


"""
    use from and give the function a different name
예제 #10
0
# In[ ]:


# 1. 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


# In[ ]:


# -import the module and refer to the function with the . syntax
import function_exercises
function_exercises.is_vowel("a")


# In[ ]:


# -use from to import the function directly
from function_exercises import is_two
is_two(2)


# In[ ]:


# -use from and give the function a different name
from function_exercises import get_letter_grade
예제 #11
0
#     - use from and give the function a different name

# In[13]:

# import the function_exercises.py file from
# my personal directory
import function_exercises
# call the function 'is_two' from my module
function_exercises.is_two(2)

# In[14]:

# from module, import the function 'is_vowel'
from function_exercises import is_vowel
# call the function 'is_vowel' to evaluate the string 'o'
is_vowel('o')

# In[15]:

# from module, import the function 'is_consonant',
# set function alias to ic
from function_exercises import is_consonant as ic
# call the function alias 'ic' to evaluate the string 'b'
ic('b')

#
# ### For the following exercises, read about and use the itertools module from the standard library to help you solve the problem.
#
# 1. How many different ways can you combine the letters from "abc" with the numbers 1, 2, and 3?
# 2. How many different ways can you combine two of the letters from "abcd"?
import function_exercises as fe

# In[2]:

print(fe.is_two(2))

# - Use `from` to import the function directly

# In[3]:

from function_exercises import is_vowel

# In[4]:

print(is_vowel('u'))

# - Use `from` and give the function a different name

# In[5]:

from function_exercises import capitalize_first_letter_if_consonant as cap

# In[6]:

print(cap('maple'))

# ### For the following exercises, read about and use the itertools module from the standard library to help you solve the problem.
# 1. How many different ways can you combine the letters from "abc" with the numbers 1, 2, and 3?

# In[7]:
# 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.
    import function_exercises
    function_exercises.is_vowel()

#     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(f'Q: How much to tip on a bill of $50.00 if we want to tip 20%? A: {calculate_tip(0.2, 50.00)}')

#     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.
    Done

# Make sure your code that tests the function imports is run from the same directory that your 
# functions exercise file is in.

# 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('Number of combinations in a,b,c to 1,2,3')
print(len(list(itertools.product('abc', '123'))))

#   - How many different combinations are there of 2 letters from "abcd"?
letter_combinations = len(list(itertools.combinations('abcd', 2)))
print(f'There are {letter_combinations} ways to combine abcd in pairs')

#   - How many different permutations are there of 2 letters from "abcd"?
예제 #14
0
assert function_exercises.is_two(2) == True
assert function_exercises.is_two('two') == False

from function_exercises import is_two

assert is_two(2) == True
assert is_two('two') == False

from function_exercises import is_two as is_it_two

assert is_it_two(2) == True
assert is_it_two('two') == False

import function_exercises

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