diff --git a/exercises/ex01/ex01.py b/exercises/ex01/ex01.py index ca880cb..ad42cfd 100644 --- a/exercises/ex01/ex01.py +++ b/exercises/ex01/ex01.py @@ -1,9 +1,6 @@ """ -# hello.py - -The window that appears should contain a cursor awaiting your input, -but it’s different from the interactive shell, which runs Python instructions -Python Basics as soon as you press enter. +Your First Program +Page 11 """ print("Nombre:") diff --git a/exercises/ex03/ex03.py b/exercises/ex03/ex03.py index b6a476a..d4ce55c 100644 --- a/exercises/ex03/ex03.py +++ b/exercises/ex03/ex03.py @@ -1,16 +1,6 @@ """ -# collatz() - -Write a function named collatz() that has one parameter named number. If -number is even, then collatz() should print number / 2 and return this value. -If number is odd, then collatz() should print and return 3 * number + 1. - -Then write a program that lets the user type in an integer and that -keeps calling collatz() on that number until the function returns the value 1. -(Amazingly enough, this sequence actually works for any integer—sooner or -later, using this sequence, you’ll arrive at 1! Even mathematicians aren’t sure -why. Your program is exploring what’s called the Collatz sequence, sometimes -called “the simplest impossible math problem.”) +Practice Projects +Page 76 """ import time diff --git a/exercises/ex04/ex04a.py b/exercises/ex04/ex04a.py index 28a292c..dfc7234 100644 --- a/exercises/ex04/ex04a.py +++ b/exercises/ex04/ex04a.py @@ -1,3 +1,9 @@ +""" +Practice Projects: Comma Code +Page 107 +""" + + def add(ls): if len(ls) > 0: ls = list(map(lambda x: str(x), ls)) diff --git a/exercises/ex04/ex04b.py b/exercises/ex04/ex04b.py index 513b90e..b7f5b74 100644 --- a/exercises/ex04/ex04b.py +++ b/exercises/ex04/ex04b.py @@ -1,3 +1,8 @@ +""" +Practice Projects: Coin Flip Streaks +Page 107 +""" + import random diff --git a/exercises/ex04/ex04c.py b/exercises/ex04/ex04c.py index 886b7fc..c3125ac 100644 --- a/exercises/ex04/ex04c.py +++ b/exercises/ex04/ex04c.py @@ -1,3 +1,8 @@ +""" +Practice Projects: Character Picture Grid +Page 108 +""" + grid = [ [".", ".", ".", ".", ".", "."], [".", "0", "0", ".", ".", "."], diff --git a/exercises/ex05/ex05a.py b/exercises/ex05/ex05a.py index 877c72d..42a949f 100644 --- a/exercises/ex05/ex05a.py +++ b/exercises/ex05/ex05a.py @@ -1,3 +1,8 @@ +""" +Practice Projects: Chess Dictionary Validator +Page 127 +""" + import sys tests = [ diff --git a/exercises/ex05/ex05b.py b/exercises/ex05/ex05b.py index 1506ad5..85d43e8 100644 --- a/exercises/ex05/ex05b.py +++ b/exercises/ex05/ex05b.py @@ -1,8 +1,13 @@ +""" +Practice Projects: Fantasy Game Inventory +Page 127 +""" + import sys tests = [ - {'rope': 1, 'torch': 6, 'gold coin': 42, 'dagger': 1, 'arrow': 12}, - {'rope': 1, 'torch': 6, 'gold coin': "a", 'dagger': 1, 'arrow': 12}, + {"rope": 1, "torch": 6, "gold coin": 42, "dagger": 1, "arrow": 12}, + {"rope": 1, "torch": 6, "gold coin": "a", "dagger": 1, "arrow": 12}, None, ] diff --git a/exercises/ex05/ex05c.py b/exercises/ex05/ex05c.py index 6e1d322..0ef3ba9 100644 --- a/exercises/ex05/ex05c.py +++ b/exercises/ex05/ex05c.py @@ -1,9 +1,14 @@ +""" +Practice Projects: List to Dictionary Function for Fantasy Game Inventory +Page 128 +""" + import sys -dragonLoot = ['gold coin', 'dagger', 'gold coin', 'gold coin', 'ruby'] +dragonLoot = ["gold coin", "dagger", "gold coin", "gold coin", "ruby"] tests = [ - {'rope': 1, 'torch': 6, 'gold coin': 42, 'dagger': 1, 'arrow': 12}, - {'rope': 1, 'torch': 6, 'gold coin': "a", 'dagger': 1, 'arrow': 12}, + {"rope": 1, "torch": 6, "gold coin": 42, "dagger": 1, "arrow": 12}, + {"rope": 1, "torch": 6, "gold coin": "a", "dagger": 1, "arrow": 12}, None, ] diff --git a/exercises/ex06/ex06a.py b/exercises/ex06/ex06a.py index a36b515..094f125 100644 --- a/exercises/ex06/ex06a.py +++ b/exercises/ex06/ex06a.py @@ -1,3 +1,8 @@ +""" +Practice Projects: Table Printer +Page 154 +""" + tableData = [ ["apples", "oranges", "cherries", "banana"], ["Alice", "Bob", "Carol", "David"], diff --git a/exercises/ex06/ex06b.py b/exercises/ex06/ex06b.py index 85da8e7..ca527d5 100644 --- a/exercises/ex06/ex06b.py +++ b/exercises/ex06/ex06b.py @@ -1,3 +1,8 @@ +""" +Practice Projects: Zombie Dice Bots +Page 155 +""" + import random import zombiedice diff --git a/exercises/ex07/ex07a.py b/exercises/ex07/ex07a.py index 46cb5c0..ff0035c 100644 --- a/exercises/ex07/ex07a.py +++ b/exercises/ex07/ex07a.py @@ -1,6 +1,12 @@ +""" +Project: Phone Number and Email Address Extractor +Page 179 +""" + import re import pyperclip + def to_int(string): string = re.sub(r"\D", "", string) if string: @@ -8,18 +14,22 @@ def to_int(string): else: return None + def rgx_phones(): return re.compile( - r"((\+(\d+)\s*)?(([ |\d|\-|\.|\(|\)]){7,}\d)(\s+ext\S*\s+(\d+))?)", re.I + r"((\+(\d+)\s*)?(([ |\d|\-|\.|\(|\)]){7,}\d)(\s+ext\S*\s+(\d+))?)", + re.I, ) + def rgx_emails(): return re.compile(r"[\w\-]+@[\w\-]+\.\w{2,}", re.I) - + + def parse_phone(phone): - lbraces = len(re.findall(r'.*\(.*', phone[0])) - rbraces = len(re.findall(r'.*\).*', phone[0])) - if lbraces == rbraces and re.match(r'^[\+|\d]', phone[0]): + lbraces = len(re.findall(r".*\(.*", phone[0])) + rbraces = len(re.findall(r".*\).*", phone[0])) + if lbraces == rbraces and re.match(r"^[\+|\d]", phone[0]): code = to_int(phone[2]) ext = to_int(phone[6]) res = to_int(phone[3]) @@ -28,9 +38,11 @@ def parse_phone(phone): res = f"{res} ext. {ext}" if ext else res return res + def get_phones(content): return list(filter(None, map(parse_phone, rgx_phones().findall(content)))) + content = pyperclip.paste() phones = get_phones(content) emails = rgx_emails().findall(content) diff --git a/exercises/ex08/ex08a.py b/exercises/ex08/ex08a.py index e3c6e33..1776396 100644 --- a/exercises/ex08/ex08a.py +++ b/exercises/ex08/ex08a.py @@ -1,29 +1,66 @@ +""" +Project: Sandwich Maker +Page 198 +""" + import pyinputplus as pyip -prices, order, total = { - "bread": { "wheat": 1.0, "white": .9, "sourdough": 1.1, }, - "protein": { "chicken": 1.0, "turkey": 1.1, "ham": .9, "tofu": .8, }, - "cheese": { "cheddar": .9, "swiss": 1.0, "mozzarella.": 1.1, } -}, {}, 0 +prices, order, total = ( + { + "bread": { + "wheat": 1.0, + "white": 0.9, + "sourdough": 1.1, + }, + "protein": { + "chicken": 1.0, + "turkey": 1.1, + "ham": 0.9, + "tofu": 0.8, + }, + "cheese": { + "cheddar": 0.9, + "swiss": 1.0, + "mozzarella.": 1.1, + }, + }, + {}, + 0, +) + def add(key, ismenu=False): isadd = pyip.inputYesNo(prompt=f"Do you want {key}? [y/n]\n") == "yes" if isadd and ismenu: - return pyip.inputMenu(list(prices[key].keys()), numbered=True, prompt=f"Please, select {key}:\n") + return pyip.inputMenu( + list(prices[key].keys()), + numbered=True, + prompt=f"Please, select {key}:\n", + ) elif isadd: return True else: return False -order["bread"] = pyip.inputMenu(list(prices["bread"].keys()), numbered=True, prompt="Please, select bread:\n") -order["protein"] = pyip.inputMenu(list(prices["protein"].keys()), numbered=True, prompt="Please, select protein:\n") +order["bread"] = pyip.inputMenu( + list(prices["bread"].keys()), + numbered=True, + prompt="Please, select bread:\n", +) +order["protein"] = pyip.inputMenu( + list(prices["protein"].keys()), + numbered=True, + prompt="Please, select protein:\n", +) order["cheese"] = add("cheese", True) order["mayo"] = add("mayo") order["mustard"] = add("mustard") order["lettuce"] = add("lettuce") order["tomato"] = add("tomato") -order["quantity"] = pyip.inputInt(prompt="How many sandwiches? [number]:\n", greaterThan=0) +order["quantity"] = pyip.inputInt( + prompt="How many sandwiches? [number]:\n", greaterThan=0 +) sandwich = "sandwich" if order["quantity"] == 1 else "sandwiches" print(f"Your order\n{order['quantity']} {sandwich} with:") @@ -39,9 +76,8 @@ for key in order.keys(): else: print(f"{prompt}NO {key}") subtotal = round(total * order["quantity"], 2) -taxes = round(subtotal * .16, 2) +taxes = round(subtotal * 0.16, 2) total = round(subtotal + taxes, 2) print(f"SUBTOTAL: {subtotal}") print(f"TAXES: {taxes}") print(f"TOTAL: {total}") - diff --git a/exercises/ex08/ex08b.py b/exercises/ex08/ex08b.py index e69de29..9306bc1 100644 --- a/exercises/ex08/ex08b.py +++ b/exercises/ex08/ex08b.py @@ -0,0 +1,4 @@ +""" +Project: Write Your Own Multiplication Quiz +Page 199 +"""