Exercises 21-24 lp3thw
This commit is contained in:
parent
347ec43263
commit
be2e5be53c
28
python/lp3thw/Exercise21/ex21.py
Normal file
28
python/lp3thw/Exercise21/ex21.py
Normal file
@ -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}")
|
||||
19
python/lp3thw/Exercise23/ex23.py
Normal file
19
python/lp3thw/Exercise23/ex23.py
Normal file
@ -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)
|
||||
97
python/lp3thw/Exercise23/languages.txt
Normal file
97
python/lp3thw/Exercise23/languages.txt
Normal file
@ -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
|
||||
文言
|
||||
吴语
|
||||
ייִדיש
|
||||
中文
|
||||
41
python/lp3thw/Exercise24/ex24.py
Normal file
41
python/lp3thw/Exercise24/ex24.py
Normal file
@ -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))
|
||||
Loading…
x
Reference in New Issue
Block a user