Add Codecademy project and ex23 PHW.

This commit is contained in:
Josh Mudge 2019-02-23 21:01:27 -07:00
parent db350ff59b
commit ea00684636
4 changed files with 5138 additions and 52 deletions

23
3exercises/ex23.py Normal file
View File

@ -0,0 +1,23 @@
import sys
script, input_encoding, error = sys.argv
def main(language_file, encoding, errors): # Define "main" function.
line = language_file.readline() # Read 1 line.
if line: # If this is true (which it will be as long as it is not the end of the file)
print_line(line, encoding, errors) # Call print_line function
return main(language_file, encoding, errors) # Call this function, the if statement will keep it from being an infinite loop. An ingenious sort of "for loop".
def print_line(line, encoding, errors): # Define print line function, which does actual encoding of lanugages.
next_lang = line.strip() # Strip trailing \n
raw_bytes = next_lang.encode(encoding, errors=errors) # Encode language from languages.txt and ecode it into raw bytes. Pass encoding argument to encode()
cooked_string = raw_bytes.decode(encoding, errors=errors) # Decode from raw bytes to a string.
print(raw_bytes, "<==>", cooked_string) # Print raw bytes on the left side, strings on the right.
languages = open("languages.txt", encoding="utf-8") # Open languages file.
main(languages, input_encoding, error) # Run main function with current paramaters and kick-start the loop.

97
3exercises/languages.txt Normal file
View 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
文言
吴语
ייִדיש
中文