diff --git a/python/lp3thw/Exercise21/ex21.py b/python/lp3thw/Exercise21/ex21.py new file mode 100644 index 0000000..7e60f23 --- /dev/null +++ b/python/lp3thw/Exercise21/ex21.py @@ -0,0 +1,28 @@ +def add(a, b): + print(f"ADDING {a} + {b}") + return a + b +def subtract(a, b): + print(f"SUBTRACTING {a} - {b}") + return a - b +def multiply(a, b): + print(f"MULTIPLYING {a} * {b}") + return a * b +def divide(a, b): + print(f"DIVIDING {a} / {b}") + return a / b + +print("Let's do some math with just functions!!") + +age = add(30, 5) +height = subtract(75, 3) +weight = multiply(60, 3) +iq = divide(200, 2) + +print(f"Age: {age} \nHeight: {height} \nWeight: {weight} \nIQ: {iq}") + +#extra credit +print("Here is a puzzle") + +what = add(age, subtract(height, multiply(weight, divide(iq, 2)))) + +print(f"The what variable is equal to: {what}") \ No newline at end of file diff --git a/python/lp3thw/Exercise23/ex23.py b/python/lp3thw/Exercise23/ex23.py new file mode 100644 index 0000000..a0aa3ae --- /dev/null +++ b/python/lp3thw/Exercise23/ex23.py @@ -0,0 +1,19 @@ +import sys +script, inputEncoding, error = sys.argv + +def main(languageFile, encoding, errors): + line = languageFile.readline() + if line: + printLine(line, encoding, errors) + return main(languageFile, encoding, errors) + +def printLine(line, encoding, errors): + nextLang = line.strip() + rawBytes = nextLang.encode(encoding, errors=errors) + cookedString = rawBytes.decode(encoding, errors=errors) + + print(rawBytes, "<===>", cookedString) + +languages = open("languages.txt", encoding="utf-8") + +main(languages, inputEncoding, error) diff --git a/python/lp3thw/Exercise23/languages.txt b/python/lp3thw/Exercise23/languages.txt new file mode 100644 index 0000000..6d47317 --- /dev/null +++ b/python/lp3thw/Exercise23/languages.txt @@ -0,0 +1,97 @@ +Afrikaans +አማርኛ +Аҧсшәа +العربية +Aragonés +Arpetan +Azərbaycanca +Bamanankan +বাংলা +Bân-lâm-gú +Беларуская +Български +Boarisch +Bosanski +Буряад +Català +Чӑвашла +Čeština +Cymraeg +Dansk +Deutsch +Eesti +Ελληνικά +Español +Esperanto +فارسی +Français +Frysk +Gaelg +Gàidhlig +Galego +한국어 +Հայերեն +हिन्दी +Hrvatski +Ido +Interlingua +Italiano +עברית +ಕನ್ನಡ +Kapampangan +ქართული +Қазақша +Kreyòl ayisyen +Latgaļu +Latina +Latviešu +Lëtzebuergesch +Lietuvių +Magyar +Македонски +Malti +मराठी +მარგალური +مازِرونی +Bahasa Melayu +Монгол +Nederlands +नेपाल भाषा +日本語 +Norsk bokmål +Nouormand +Occitan +Oʻzbekcha/ўзбекча +ਪੰਜਾਬੀ +پنجابی +پښتو +Plattdüütsch +Polski +Português +Română +Romani +Русский +Seeltersk +Shqip +Simple English +Slovenčina +کوردیی ناوەندی +Српски / srpski +Suomi +Svenska +Tagalog +தமிழ் +ภาษาไทย +Taqbaylit +Татарча/tatarça +తెలుగు +Тоҷикӣ +Türkçe +Українська +اردو +Tiếng Việt +Võro +文言 +吴语 +ייִדיש +中文 diff --git a/python/lp3thw/Exercise24/ex24.py b/python/lp3thw/Exercise24/ex24.py new file mode 100644 index 0000000..d0ea1ac --- /dev/null +++ b/python/lp3thw/Exercise24/ex24.py @@ -0,0 +1,41 @@ +print("Let's practice everything.") +print("You'd need to know about escapes with \\") +print("\n newlines and \ttabs") + +poem = """ +\tThe lovely world +with logic so firmly planted +cannot discern \n the needs of love +nor comprehend passion from intuition +and requires an explanation +\n\t\twhere there is none. +""" + +print("-----------") +print(poem) +print("-----------") + + +five = 10 - 2 + 3 - 6 +print(f"this should be five: {five}") + +def secretFormula(started): + jellyBeans = started * 500 + jars = jellyBeans / 1000 + crates = jars / 100 + return jellyBeans, jars, crates + + +startPoint = 10000 +beans, jars, crates = secretFormula(startPoint) + +#another way to format a string +print("With a starting point of {}".format(startPoint)) +#Identical to the print(f" ") method +print(f"We have {beans} beans, {jars} jars, and {crates} crates.") + +startPoint = startPoint / 10 + +print("We can also do that this way:") +formula = secretFormula(startPoint) +print("We'd have {} beans, {} jars, {} crates".format(*formula)) \ No newline at end of file