Merge branch 'master' of code.ungleich.ch:ungleich-public/ungleich-learning-circle
This commit is contained in:
commit
9c7d1f4909
43 changed files with 1520 additions and 31 deletions
13
balazs/python-the-hard-way/ex12/notes.org
Normal file
13
balazs/python-the-hard-way/ex12/notes.org
Normal file
|
@ -0,0 +1,13 @@
|
|||
|
||||
|
||||
* The code:
|
||||
age = input("How old are you? ")
|
||||
height = input("How tall are you? ")
|
||||
weight = input("How much do you weigh? ")
|
||||
|
||||
|
||||
print(f"So, you're {age} old, {height} tall and {weight} heavy.")
|
||||
|
||||
* When will input run? At the variable initalization or when calling the function?
|
||||
|
||||
* How do I debug, and step through the code to see what's happening in the background (and possibly see the anwser for the prev question)?
|
24
balazs/python-the-hard-way/ex17/notes.org
Normal file
24
balazs/python-the-hard-way/ex17/notes.org
Normal file
|
@ -0,0 +1,24 @@
|
|||
* Questions
|
||||
|
||||
** Why does Opening and Reading the file is done in 2 steps? What's the difference?
|
||||
in_file = open(from_file)
|
||||
indata = in_file.read()
|
||||
|
||||
"Opening" a file doesn't actually bring any of the data from the file into your program. It just prepares the file for reading (or writing), so when your program is ready to read the contents of the file it can do so right away.
|
||||
*** Source:
|
||||
https://stackoverflow.com/questions/20308998/what-is-the-difference-between-opening-and-reading-a-file-in-python
|
||||
|
||||
** What does 'w' mean? (from ex16)
|
||||
target = open(filename, 'w')
|
||||
|
||||
It's a string with a character in it for the kind of mode for the file.
|
||||
|
||||
'w' = write
|
||||
'r' = read
|
||||
'a' = append
|
||||
|
||||
|
||||
|
||||
* Note
|
||||
|
||||
" character messes up the copy in org or emacs
|
25
balazs/python-the-hard-way/ex23/convertor.py
Normal file
25
balazs/python-the-hard-way/ex23/convertor.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
import sys
|
||||
script, input_encoding, error = sys.argv
|
||||
|
||||
print (sys.argv)
|
||||
|
||||
def main(language_file, encoding, errors):
|
||||
|
||||
line = language_file.readline()
|
||||
print (line)
|
||||
|
||||
if line:
|
||||
print_line(line, encoding, errors)
|
||||
return main(language_file, encoding, errors)
|
||||
|
||||
def print_line(line, encoding, errors):
|
||||
next_lang = line.strip()
|
||||
raw_bytes = next_lang.encode(encoding, errors=errors)
|
||||
cooked_string = raw_bytes.decode(encoding, errors=errors)
|
||||
|
||||
print(raw_bytes, "<===>", cooked_string)
|
||||
|
||||
|
||||
languages = open("languages.txt", encoding="utf-8")
|
||||
|
||||
main(languages, input_encoding, error)
|
97
balazs/python-the-hard-way/ex23/languages.txt
Normal file
97
balazs/python-the-hard-way/ex23/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
|
||||
文言
|
||||
吴语
|
||||
ייִדיש
|
||||
中文
|
32
balazs/python-the-hard-way/ex23/notes
Normal file
32
balazs/python-the-hard-way/ex23/notes
Normal file
|
@ -0,0 +1,32 @@
|
|||
* Questions:
|
||||
|
||||
** How does the program reads the file?
|
||||
readline
|
||||
|
||||
** How does it loops over the lines?
|
||||
readline will return an empty string when no more data is available
|
||||
|
||||
*** https://stackoverflow.com/questions/28936140/use-readline-to-read-txt-file-python3
|
||||
|
||||
** Why doesnt he uses a for loop? (instead of return) -later
|
||||
|
||||
Good to know:
|
||||
|
||||
"The second method still reads the file line by line and does not load the whole file into memory, right? – nishant Nov 14 '19 at 7:24"
|
||||
"@nishant correct – Ilan Kleiman Dec 15 '19 at 1:42"
|
||||
|
||||
|
||||
** What is "with" in python? -later
|
||||
|
||||
** Why should I use builting python utils instead of *nix utils? -later
|
||||
|
||||
|
||||
|
||||
* Notes:
|
||||
|
||||
strip: for text formatting
|
||||
|
||||
|
||||
* Log:
|
||||
|
||||
Takes a long time to watch the video.
|
21
balazs/python-the-hard-way/ex31/mountain.py
Normal file
21
balazs/python-the-hard-way/ex31/mountain.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
|
||||
|
||||
while True:
|
||||
print("""You are on a mountain.
|
||||
There is a smaller mountain ahead of you and there is a bigger mountain behind you.""")
|
||||
|
||||
print("Where do you go?")
|
||||
|
||||
print("""1. Forward
|
||||
2. Backward""")
|
||||
|
||||
direction = input("> ")
|
||||
|
||||
if direction == "1":
|
||||
print("You continued your journey forward, and you arrived on a smaller mountain.")
|
||||
|
||||
elif direction == "2":
|
||||
print("You continued your journey backward, and you arrived on a bigger mountain.")
|
||||
|
||||
else:
|
||||
print("You decided to rest, and decide later")
|
44
balazs/python-the-hard-way/ex32/notes_n_drills.org
Normal file
44
balazs/python-the-hard-way/ex32/notes_n_drills.org
Normal file
|
@ -0,0 +1,44 @@
|
|||
* Drills
|
||||
|
||||
** Take a look at how you used range . Look up the range function to understand it.
|
||||
|
||||
tldr, a "function" that generates a sequence of numbers:
|
||||
|
||||
|
||||
class range(start, stop[, step]):
|
||||
start
|
||||
|
||||
The value of the start parameter (or 0 if the parameter was not supplied)
|
||||
|
||||
stop
|
||||
|
||||
The value of the stop parameter
|
||||
|
||||
step
|
||||
|
||||
The value of the step parameter (or 1 if the parameter was not supplied)
|
||||
|
||||
-------
|
||||
|
||||
I found it among python 3.8.3 built-in functions.
|
||||
|
||||
but!
|
||||
|
||||
Turns out it's not a function after all!
|
||||
|
||||
It's an immutable sequence type.
|
||||
|
||||
"a range object will always take the same (small) amount of memory" ... "as it only stores the start, stop and step values" and generates numbers on the fly
|
||||
|
||||
note: similar in shell is: seq
|
||||
source: https://docs.python.org/3/library/stdtypes.html#range
|
||||
|
||||
** Could you have avoided that for-loop entirely on line 22 and just assigned range(0,6) directly to elements?
|
||||
Do you mean line 21 book? (typo)
|
||||
|
||||
Yes! Because range will generate a list that can be appended added as is.
|
||||
** Find the Python documentation on lists and read about them. What other operations can you do to lists besides append?
|
||||
|
||||
extend, insert, remove, pop, clear, index, count, sort, reverse, copy
|
||||
|
||||
fascinating! programming is cool! you can do so much with it
|
22
balazs/python-the-hard-way/ex33/ex33.py
Normal file
22
balazs/python-the-hard-way/ex33/ex33.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
#i = 0
|
||||
numbers = []
|
||||
|
||||
def counter(i2, INC_BY):
|
||||
|
||||
i = 0
|
||||
|
||||
while i < i2 :
|
||||
print(f"At the top i is {i}")
|
||||
numbers.append(i)
|
||||
|
||||
i = i + INC_BY
|
||||
|
||||
print("Nums now:", numbers)
|
||||
print(f"At the bottom i is {i}")
|
||||
|
||||
print("The numbers: ")
|
||||
|
||||
for num in numbers:
|
||||
print(num)
|
||||
|
||||
counter(2, 2)
|
6
balazs/python-the-hard-way/ex34/notes_n_drills.org
Normal file
6
balazs/python-the-hard-way/ex34/notes_n_drills.org
Normal file
|
@ -0,0 +1,6 @@
|
|||
* Drills
|
||||
|
||||
** With what you know of the difference between these types of numbers, can you explain why the year 2010 in ”January 1, 2010,” really is 2010 and not 2009? (Hint: you can’t pick years at random.)
|
||||
|
||||
What is this question? :/
|
||||
|
84
balazs/python-the-hard-way/ex35/ex35.py
Normal file
84
balazs/python-the-hard-way/ex35/ex35.py
Normal file
|
@ -0,0 +1,84 @@
|
|||
from sys import exit
|
||||
import time
|
||||
|
||||
def gold_room():
|
||||
print("This room is full of gold. How much do you take?")
|
||||
|
||||
choice = input("> ")
|
||||
if "0" in choice or "1" in choice:
|
||||
how_much = int(choice)
|
||||
else:
|
||||
dead("Man, learn to type a number.")
|
||||
|
||||
if how_much < 50:
|
||||
print("Nice, you're not greedy, you win!")
|
||||
exit(0)
|
||||
else:
|
||||
dead("You greedy bastard!")
|
||||
|
||||
|
||||
def bear_room():
|
||||
print("There is bear here.")
|
||||
print("The bear has a bunch of honey.")
|
||||
print("The fat bear is in front of another door.")
|
||||
print("How are you going to move the bear?")
|
||||
bear_moved = False
|
||||
|
||||
while True:
|
||||
choice = input("> ")
|
||||
|
||||
if choice == "take honey":
|
||||
dead("The bear looks at you then slaps your face off.")
|
||||
elif choice == "taunt bear" and not bear_moved:
|
||||
print("The bear has moved from the door.")
|
||||
print("You can go through it now.")
|
||||
bear_moved = True
|
||||
elif choice == "tea" and not bear_moved:
|
||||
print("You have invited the bear for a tea.")
|
||||
time.sleep(1)
|
||||
print("The bear is happy and moved.")
|
||||
bear_moved = True
|
||||
elif choice == "taunt bear" and bear_moved:
|
||||
dead("The bear gets pissed off and chews your leg off.")
|
||||
elif choice == "open door" and bear_moved:
|
||||
gold_room()
|
||||
else:
|
||||
print("I got no idea what that means.")
|
||||
|
||||
|
||||
def cthulhu_room():
|
||||
print("Here you see the great evil Cthulhu.")
|
||||
print("He, it, whatever stares at you and you go insane.")
|
||||
print("Do you flee for your life or eat your head?")
|
||||
|
||||
choice = input("> ")
|
||||
|
||||
if "flee" in choice:
|
||||
start()
|
||||
elif "head" in choice:
|
||||
dead("Well that was tasty!")
|
||||
else:
|
||||
cthulhu_room()
|
||||
|
||||
|
||||
def dead(why):
|
||||
print(why, "Good job!")
|
||||
exit(0)
|
||||
|
||||
|
||||
def start():
|
||||
print("You are in a dark room.")
|
||||
print("There is a door to your right and left.")
|
||||
print("Which one do you take?")
|
||||
|
||||
choice = input("> ")
|
||||
|
||||
if choice == "left":
|
||||
bear_room()
|
||||
elif choice == "right":
|
||||
cthulhu_room()
|
||||
else:
|
||||
dead("You stumble around the room until you starve.")
|
||||
|
||||
|
||||
start()
|
10
balazs/python-the-hard-way/ex35/notes_n_drills.org
Normal file
10
balazs/python-the-hard-way/ex35/notes_n_drills.org
Normal file
|
@ -0,0 +1,10 @@
|
|||
*Drills
|
||||
|
||||
** The gold_room has a weird way of getting you to type a number. What are all the bugs in this way of doing it? Can you make it better than what I’ve written? Look at how int() works for clues.
|
||||
|
||||
Non greedy is less than 50 but only 1 and 0 qualify.
|
||||
|
||||
Nicer ways:
|
||||
-> check for numbers
|
||||
-> also check for None and All strings
|
||||
-> sanitize input for int(), (int can take 2 variables)
|
Binary file not shown.
|
@ -1,8 +0,0 @@
|
|||
n
|
||||
print("Hello World!")
|
||||
print("Hello Again")
|
||||
print("I like typing this.")
|
||||
print("This is fun.")
|
||||
print('Yay! Printing.')
|
||||
print("I'd much rather you 'not'.")
|
||||
print('I "said" do not touch this.')
|
|
@ -1 +0,0 @@
|
|||
sami@afro-linux-lenovo-b50-30.19806:1589891645
|
3
sami/learn-python-the-hard-way/ex15_sample.txt
Normal file
3
sami/learn-python-the-hard-way/ex15_sample.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
This is stuff I typed into a file.
|
||||
It is really cool stuff.
|
||||
Lots and lots of fun to have in here.
|
|
@ -1,22 +1,20 @@
|
|||
# this one is like your scripts with argv
|
||||
def print_two(*args):
|
||||
arg1, arg2 = args
|
||||
print(f"arg1: {arg1}, arg2: {arg2}")
|
||||
arg1, arg2 = args
|
||||
print(f"arg1: {arg1}, arg2: {arg2}")
|
||||
|
||||
# ok, that *args is actually pointless, we can just do this
|
||||
def print_two_again(arg1, arg2):
|
||||
|
||||
print(f"arg1: {arg1}, arg2: {arg2}")
|
||||
print(f"arg1: {arg1}, arg2: {arg2}")
|
||||
|
||||
# this just takes one argument
|
||||
def print_one(arg1):
|
||||
|
||||
print(f"arg1: {arg1}")
|
||||
print(f"arg1: {arg1}")
|
||||
|
||||
# this one takes no arguments
|
||||
def print_none():
|
||||
print("I got nothin'.")
|
||||
|
||||
print("I got nothin'.")
|
||||
|
||||
|
||||
print_two("Zed","Shaw")
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
def cheese_and_crackers(cheese_count, boxes_of_crackers):
|
||||
print(f"You have {cheese_count} cheeses!")
|
||||
print(f"You have {boxes_of_crackers} boxes of crackers!")
|
||||
print("Man that's enough for a party!")
|
||||
print("Get a blanket.\n")
|
||||
print(f"You have {cheese_count} cheeses!")
|
||||
print(f"You have {boxes_of_crackers} boxes of crackers!")
|
||||
print("Man that's enough for a party!")
|
||||
print("Get a blanket.\n")
|
||||
|
||||
|
||||
print("We can just give the function numbers directly:")
|
||||
|
|
|
@ -6,17 +6,17 @@ script, input_file = argv
|
|||
|
||||
|
||||
def print_all(f):
|
||||
print(f.read())
|
||||
print(f.read())
|
||||
|
||||
|
||||
|
||||
def rewind(f):
|
||||
f.seek(0)
|
||||
f.seek(0)
|
||||
|
||||
|
||||
|
||||
def print_a_line(line_count, f):
|
||||
print(line_count, f.readline())
|
||||
print(line_count, f.readline())
|
||||
|
||||
|
||||
current_file = open(input_file)
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
def add(a, b):
|
||||
print(f"ADDING {a} + {b}")
|
||||
return a + b
|
||||
print(f"ADDING {a} + {b}")
|
||||
return a + b
|
||||
|
||||
|
||||
def subtract(a, b):
|
||||
print(f"SUBTRACTING {a} - {b}")
|
||||
return a - b
|
||||
print(f"SUBTRACTING {a} - {b}")
|
||||
return a - b
|
||||
|
||||
|
||||
def multiply(a, b):
|
||||
print(f"MULTIPLYING {a} * {b}")
|
||||
return a * b
|
||||
print(f"MULTIPLYING {a} * {b}")
|
||||
return a * b
|
||||
|
||||
|
||||
def divide(a, b):
|
||||
print(f"DIVIDING {a} / {b}")
|
||||
return a / b
|
||||
print(f"DIVIDING {a} / {b}")
|
||||
return a / b
|
||||
|
||||
|
||||
print("Let's do some math with just functions!")
|
||||
|
|
31
sami/learn-python-the-hard-way/ex23.py
Normal file
31
sami/learn-python-the-hard-way/ex23.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
import sys
|
||||
script, input_encoding, error = sys.argv
|
||||
|
||||
|
||||
def main(language_file, encoding, errors):
|
||||
line = language_file.readline()
|
||||
|
||||
|
||||
|
||||
|
||||
if line:
|
||||
print_line(line, encoding, errors)
|
||||
return main(language_file, encoding, errors)
|
||||
|
||||
|
||||
|
||||
def print_line(line, encoding, errors):
|
||||
next_lang = line.strip()
|
||||
raw_bytes = next_lang.encode(encoding, errors=errors)
|
||||
cooked_string = raw_bytes.decode(encoding, errors=errors)
|
||||
|
||||
|
||||
print(raw_bytes, "<===>", cooked_string)
|
||||
|
||||
|
||||
|
||||
languages = open("languages.txt", encoding="utf-8")
|
||||
|
||||
|
||||
|
||||
main(languages, input_encoding, error)
|
46
sami/learn-python-the-hard-way/ex24.py
Normal file
46
sami/learn-python-the-hard-way/ex24.py
Normal file
|
@ -0,0 +1,46 @@
|
|||
print("Let's practice everything.")
|
||||
print('You\'d need to know \'bout escapes with \\ that do:')
|
||||
print('\n newlines and \t tabs.')
|
||||
|
||||
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 secret_formula(started):
|
||||
jelly_beans = started * 500
|
||||
jars = jelly_beans / 1000
|
||||
crates = jars / 100
|
||||
return jelly_beans, jars, crates
|
||||
|
||||
|
||||
start_point = 10000
|
||||
beans, jars, crates = secret_formula(start_point)
|
||||
|
||||
#remember that this is another way to format a string
|
||||
print("With a starting point of: {}".format(start_point))
|
||||
|
||||
# it's just like with an f"" string
|
||||
print(f"We'd have {beans} beans, {jars} jars, and {crates} crates.")
|
||||
|
||||
|
||||
|
||||
start_point = start_point / 10
|
||||
|
||||
print("We can also do that this way:")
|
||||
formula = secret_formula(start_point)
|
||||
# this is an easy way to apply a list to a format string
|
||||
print("We'd have {} beans, {} jars, and {} crates.".format(*formula))
|
36
sami/learn-python-the-hard-way/ex25.py
Normal file
36
sami/learn-python-the-hard-way/ex25.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
|
||||
def break_words(stuff):
|
||||
"""This function will break up words for us."""
|
||||
words = stuff.split(' ')
|
||||
return words
|
||||
|
||||
|
||||
def sort_words(words):
|
||||
"""Sorts the words."""
|
||||
return sorted(words)
|
||||
|
||||
|
||||
def print_first_word(words):
|
||||
"""Prints the first word after popping it off."""
|
||||
word = words.pop(0)
|
||||
print(word)
|
||||
|
||||
|
||||
def print_last_word(words):
|
||||
"""Prints the last word after popping it off."""
|
||||
word = words.pop(-1)
|
||||
print(word)
|
||||
|
||||
|
||||
def sort_sentence(sentence):
|
||||
"""Takes in a full sentence and returns the sorted words."""
|
||||
words = break_words(sentence)
|
||||
return sort_words(words)
|
||||
|
||||
|
||||
def print_first_and_last(sentence):
|
||||
"""Prints the first and last words of the sentence."""
|
||||
words = break_words(sentence)
|
||||
print_first_word(words)
|
||||
print_last_word(words)
|
||||
|
27
sami/learn-python-the-hard-way/ex28.py
Normal file
27
sami/learn-python-the-hard-way/ex28.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
3 == 3 and (not ("testing" == "testing" or "Python" == "Fun"))
|
||||
False
|
||||
|
||||
3 == 3 and (not ("testing" == "testing" or False))
|
||||
False
|
||||
|
||||
3 == 3 and (not (True or "Python" == "Fun"))
|
||||
False
|
||||
|
||||
3 == 3 and (not (True or False))
|
||||
False
|
||||
|
||||
3 == 3 and (not ("True"))
|
||||
False
|
||||
|
||||
3 == 3 and False
|
||||
False
|
||||
|
||||
True and False
|
||||
False
|
||||
|
||||
|
||||
|
||||
True and False or False and True
|
||||
False or False and True
|
||||
False and False
|
||||
False
|
41
sami/learn-python-the-hard-way/ex29.py
Normal file
41
sami/learn-python-the-hard-way/ex29.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
people = 20
|
||||
cats = 30
|
||||
dogs = 15
|
||||
|
||||
|
||||
|
||||
|
||||
if people < cats:
|
||||
print("Too many cats! The world is doomed!")
|
||||
|
||||
|
||||
|
||||
if people > cats:
|
||||
print("Not many cats! The world is saved!")
|
||||
|
||||
|
||||
|
||||
if people < dogs:
|
||||
print("The world is drooled on!")
|
||||
|
||||
|
||||
|
||||
if people > dogs:
|
||||
print("The world is dry!")
|
||||
|
||||
|
||||
|
||||
dogs += 5
|
||||
|
||||
|
||||
|
||||
if people >= dogs:
|
||||
print("People are greater than or equal to dogs.")
|
||||
|
||||
|
||||
if people <= dogs:
|
||||
print("People are less than or equal to dogs.")
|
||||
|
||||
|
||||
if people == dogs:
|
||||
print("People are dogs.")
|
27
sami/learn-python-the-hard-way/ex30.py
Normal file
27
sami/learn-python-the-hard-way/ex30.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
people = 30
|
||||
cars = 40
|
||||
trucks = 15
|
||||
|
||||
|
||||
|
||||
if cars > people:
|
||||
print("We should take the cars.")
|
||||
elif cars < people:
|
||||
print("We should not take the cars.")
|
||||
else:
|
||||
print("We can't decide.")
|
||||
|
||||
|
||||
|
||||
if trucks > cars:
|
||||
print("That's too many trucks.")
|
||||
elif trucks < cars:
|
||||
print("Maybe we could take the trucks.")
|
||||
else:
|
||||
print("We still can't decide.")
|
||||
|
||||
|
||||
if people > trucks:
|
||||
print("Alright, let's just take the trucks.")
|
||||
else:
|
||||
print("Fine, let's stay home then.")
|
43
sami/learn-python-the-hard-way/ex31.py
Normal file
43
sami/learn-python-the-hard-way/ex31.py
Normal file
|
@ -0,0 +1,43 @@
|
|||
print("""You enter a dark room with two doors.
|
||||
Do you go through door #1 or door #2?""")
|
||||
|
||||
|
||||
door = input("> ")
|
||||
|
||||
|
||||
if door == "1":
|
||||
print("There's a giant bear here eating a cheese cake.")
|
||||
print("What do you do?")
|
||||
print("1. Take the cake.")
|
||||
print("2. Scream at the bear.")
|
||||
|
||||
bear = input("> ")
|
||||
|
||||
if bear == "1":
|
||||
print("The bear eats your face off. Good job!")
|
||||
elif bear == "2":
|
||||
print("The bear eats your legs off. Good job!")
|
||||
else:
|
||||
print(f"Well, doing {bear} is probably better.")
|
||||
print("Bear runs away.")
|
||||
|
||||
elif door == "2":
|
||||
print("You stare into the endless abyss at Cthulhu's retina.")
|
||||
print("1. Blueberries.")
|
||||
print("2. Yellow jacket clothespins.")
|
||||
print("3. Understanding revolvers yelling melodies.")
|
||||
|
||||
|
||||
insanity = input("> ")
|
||||
|
||||
|
||||
if insanity == "1" or insanity == "2":
|
||||
print("Your body survives powered by a mind of jello.")
|
||||
print("Good job!")
|
||||
else:
|
||||
print("The insanity rots your eyes into a pool of muck.")
|
||||
print("Good job!")
|
||||
|
||||
|
||||
else:
|
||||
print("You stumble around and fall on a knife and die. Good job!")
|
97
sami/learn-python-the-hard-way/languages.txt
Normal file
97
sami/learn-python-the-hard-way/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
|
||||
文言
|
||||
吴语
|
||||
ייִדיש
|
||||
中文
|
|
@ -1,3 +1,27 @@
|
|||
* 2020-05-29
|
||||
*** Python #6:
|
||||
**** DONE Lecture content
|
||||
CLOSED: [2020-05-29 금 23:48]
|
||||
- Same structure as "Python #2"
|
||||
- Exercises 32-36
|
||||
**** Lecture material
|
||||
- Available on https://cloud.ungleich.ch/s/435FyfrQyEq6oF3
|
||||
* 2020-05-27
|
||||
*** Python #5:
|
||||
**** DONE Lecture content
|
||||
CLOSED: [2020-05-27 수 22:30]
|
||||
- Same structure as "Python #2"
|
||||
- Exercises 27-31
|
||||
**** Lecture material
|
||||
- Available on https://cloud.ungleich.ch/s/435FyfrQyEq6oF3
|
||||
* 2020-05-25
|
||||
*** Python #4:
|
||||
**** DONE Lecture content
|
||||
CLOSED: [2020-05-27 수 22:41]
|
||||
- Same structure as "Python #2"
|
||||
- Exercises 23-26
|
||||
**** Lecture material
|
||||
- Available on https://cloud.ungleich.ch/s/435FyfrQyEq6oF3
|
||||
* 2020-05-22
|
||||
**** DONE Lecture content
|
||||
CLOSED: [2020-05-23 토 00:21]
|
||||
|
|
23
youngjin.han/python-the-hard-way/ex23.py
Normal file
23
youngjin.han/python-the-hard-way/ex23.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
import sys
|
||||
script, input_encoding, error = sys.argv
|
||||
|
||||
|
||||
def main(language_file, encoding, errors):
|
||||
line = language_file.readline()
|
||||
|
||||
if line:
|
||||
print_line(line, encoding, errors)
|
||||
return main(language_file, encoding, errors)
|
||||
|
||||
|
||||
def print_line(line, encoding, errors):
|
||||
next_lang = line.strip()
|
||||
raw_bytes = next_lang.encode(encoding, errors=errors)
|
||||
cooked_string = raw_bytes.decode(encoding, errors=errors)
|
||||
|
||||
print(raw_bytes, "<===>", cooked_string)
|
||||
|
||||
|
||||
languages = open("languages.txt", encoding="utf-8")
|
||||
|
||||
main(languages, input_encoding, error)
|
43
youngjin.han/python-the-hard-way/ex24.py
Normal file
43
youngjin.han/python-the-hard-way/ex24.py
Normal file
|
@ -0,0 +1,43 @@
|
|||
print("Let's practice everything.") # print a script
|
||||
print('You\'d need to know \'bout escapes with \\ that do:') # print a script
|
||||
print('\n newlines and \t tabs.') # print a script
|
||||
|
||||
# define a string array
|
||||
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 a script
|
||||
print(poem) # print a script
|
||||
print("--------------") # print a script
|
||||
|
||||
|
||||
five = 10 - 2 + 3 - 6 # calculate a number
|
||||
print(f"This should be five: {five}") # print a script
|
||||
|
||||
def secret_formula(started): # define a function
|
||||
jelly_beans = started * 500 # calculate a number
|
||||
jars = jelly_beans / 1000 # calculate a number
|
||||
crates = jars / 100 # calculate a number
|
||||
return jelly_beans, jars, crates # return values
|
||||
|
||||
|
||||
start_point = 10000 # define a value
|
||||
beans, jars, crates = secret_formula(start_point) # run a function
|
||||
|
||||
# remember that this is another way to format a string
|
||||
print("With a starting point of: {}".format(start_point)) # print a script
|
||||
# it's just like with an f"" string
|
||||
print(f"We'd have {beans} beans, {jars} jars, and {crates} crates.") # print a script
|
||||
|
||||
start_point = start_point / 10 # calculate a number
|
||||
|
||||
print("We can also do that this way:") # print a script
|
||||
formula = secret_formula(start_point) # run a function
|
||||
# this is an easy way to apply a list to a format string
|
||||
print("We'd have {} beans, {} jars, and {} crates.".format(*formula)) # print a script
|
35
youngjin.han/python-the-hard-way/ex25.py
Normal file
35
youngjin.han/python-the-hard-way/ex25.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
def break_words(stuff):
|
||||
"""This function will break up words for us."""
|
||||
words = stuff.split(' ')
|
||||
return words
|
||||
|
||||
def sort_words(words):
|
||||
"""Sorts the words."""
|
||||
return sorted(words)
|
||||
|
||||
def print_first_word(words):
|
||||
"""Prints the first word after popping it off."""
|
||||
word = words.pop(0)
|
||||
print(word)
|
||||
|
||||
def print_last_word(words):
|
||||
"""Prints the last word after popping it off."""
|
||||
word = words.pop(-1)
|
||||
print(word)
|
||||
|
||||
def sort_sentence(sentence):
|
||||
"""Takes in a full sentence and returns the sorted words."""
|
||||
words = break_words(sentence)
|
||||
return sort_words(words)
|
||||
|
||||
def print_first_and_last(sentence):
|
||||
"""Prints the first and last words of the sentence."""
|
||||
words = break_words(sentence)
|
||||
print_first_word(words)
|
||||
print_last_word(words)
|
||||
|
||||
def print_first_and_last_sorted(sentence):
|
||||
"""Sorts the words then prints the first and last one."""
|
||||
words = sort_sentence(sentence)
|
||||
print_first_word(words)
|
||||
print_last_word(words)
|
101
youngjin.han/python-the-hard-way/ex26.py
Normal file
101
youngjin.han/python-the-hard-way/ex26.py
Normal file
|
@ -0,0 +1,101 @@
|
|||
import sys
|
||||
|
||||
print("How old are you?", end=' ')
|
||||
age = input()
|
||||
print("How tall are you?", end=' ')
|
||||
height = input()
|
||||
print("How much do you weigh?", end=' ')
|
||||
weight = input()
|
||||
|
||||
print(f"So, you're {age} old, {height} tall and {weight} heavy.")
|
||||
|
||||
script, filename = sys.argv
|
||||
|
||||
txt = open(filename)
|
||||
|
||||
print("Here's your file {filename}:")
|
||||
print(txt.read())
|
||||
|
||||
print("Type the filename again:")
|
||||
file_again = input("> ")
|
||||
|
||||
txt_again = open(file_again)
|
||||
|
||||
print(txt_again.read())
|
||||
|
||||
|
||||
print("Let's practice everything.")
|
||||
print("""You\'d need to know \'bout escapes
|
||||
with \\ that do \n newlines and \t tabs.""")
|
||||
|
||||
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 secret_formula(started):
|
||||
jelly_beans = started * 500
|
||||
jars = jelly_beans / 1000
|
||||
crates = jars / 100
|
||||
return jelly_beans, jars, crates
|
||||
|
||||
|
||||
start_point = 10000
|
||||
beans, jars, crates = secret_formula(start_point)
|
||||
|
||||
# remember that this is another way to format a string
|
||||
print("With a starting point of: {}".format(start_point))
|
||||
# it's just like with an f"" string
|
||||
print(f"We'd have {beans} beans, {jars} jars, and {crates} crates.")
|
||||
|
||||
start_point = start_point / 10
|
||||
|
||||
print("We can also do that this way:")
|
||||
formula = secret_formula(start_point)
|
||||
# this is an easy way to apply a list to a format string
|
||||
print("We'd have {} beans, {} jars, and {} crates.".format(*formula))
|
||||
|
||||
|
||||
|
||||
people = 20
|
||||
cats = 30
|
||||
dogs = 15
|
||||
|
||||
|
||||
if people < cats:
|
||||
print ("Too many cats! The world is doomed!")
|
||||
|
||||
if people < cats:
|
||||
print("Not many cats! The world is saved!")
|
||||
|
||||
if people < dogs:
|
||||
print("The world is drooled on!")
|
||||
|
||||
if people > dogs:
|
||||
print("The world is dry!")
|
||||
|
||||
|
||||
dogs += 5
|
||||
|
||||
if people >= dogs:
|
||||
print("People are greater than or equal to dogs.")
|
||||
|
||||
if people <= dogs:
|
||||
print("People are less than or equal to dogs.")
|
||||
|
||||
|
||||
if people == dogs:
|
||||
print("People are dogs.")
|
||||
|
32
youngjin.han/python-the-hard-way/ex29.py
Normal file
32
youngjin.han/python-the-hard-way/ex29.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
people = 20
|
||||
cats = 30
|
||||
dogs = 15
|
||||
|
||||
|
||||
if people < cats:
|
||||
print("Too many cats! The world is doomed!")
|
||||
|
||||
if people > cats:
|
||||
print("Not many cats! The world is saved!")
|
||||
|
||||
if people < dogs:
|
||||
print("The world is drooled on!")
|
||||
|
||||
if people > dogs:
|
||||
print("The world is dry!")
|
||||
|
||||
if people != dogs:
|
||||
print("People are not dogs.")
|
||||
|
||||
dogs += 5
|
||||
|
||||
if people >= dogs:
|
||||
print("People are greater than or equal to dogs.")
|
||||
|
||||
if people <= dogs:
|
||||
print("People are less than or equal to dogs.")
|
||||
|
||||
|
||||
if people == dogs:
|
||||
print("People are dogs.")
|
||||
|
28
youngjin.han/python-the-hard-way/ex30.py
Normal file
28
youngjin.han/python-the-hard-way/ex30.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
people = 3 # define a value
|
||||
cars = 4 # define a value
|
||||
trucks = 1 #define a value
|
||||
|
||||
|
||||
if cars > people: # test a criteria
|
||||
print("We should take the cars.") # print a script
|
||||
elif cars < people: # test a criteria
|
||||
print("We should not take the cars.") # print a script
|
||||
else: # test a criteria
|
||||
print("We can't decide.") # print a script
|
||||
|
||||
if trucks > cars: # test a criteria
|
||||
print("That's too many trucks.") # print a script
|
||||
elif trucks < cars: # test a criteria
|
||||
print("Maybe we could take the trucks.") # print a script
|
||||
else: # test a criteria
|
||||
print("We still can't decide.") # print a script
|
||||
|
||||
if people > trucks: # test a criteria
|
||||
print("Alright, let's just take the trucks.") # print a script
|
||||
else: # test a criteria
|
||||
print("Fine, let's stay home then.") # print a script
|
||||
|
||||
if cars > people or trucks < cars: # test a criteria
|
||||
print("There are a lot of cars") # print a script
|
||||
else: # test a criteria
|
||||
print("There are a few cars") # print a script
|
20
youngjin.han/python-the-hard-way/ex31-1.py
Normal file
20
youngjin.han/python-the-hard-way/ex31-1.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
from random import *
|
||||
|
||||
print("""Please, Press 'Enter' on your keyboard to roll a dice.""")
|
||||
dumy = input("> ")
|
||||
dice = randint(1, 6)
|
||||
|
||||
print("""Guess the dice number. and then,
|
||||
Please, Input it.""")
|
||||
your_number = input("> ")
|
||||
|
||||
if int(your_number) > 6:
|
||||
print("WRONG NUMBER!!!!")
|
||||
else:
|
||||
if int(your_number) > dice:
|
||||
print(f"Your number is bigger than dice is {dice}")
|
||||
elif int(your_number) == dice:
|
||||
print(f"Your number is equal to dice is {dice}")
|
||||
elif int(your_number) < dice:
|
||||
print(f"Your number is less than dice is {dice}")
|
||||
|
41
youngjin.han/python-the-hard-way/ex31.py
Normal file
41
youngjin.han/python-the-hard-way/ex31.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
print("""You enter a dark room with two doors.
|
||||
Do you go through door #1 or door #2?""")
|
||||
|
||||
door = input("> ")
|
||||
|
||||
if door == "1":
|
||||
print("There's a giant bear here eating a cheese cake.")
|
||||
print("What do you do?")
|
||||
print("1. Take the cake.")
|
||||
print("2. Scream at the bear.")
|
||||
print("3. Call 911.")
|
||||
|
||||
bear = input("> ")
|
||||
|
||||
if bear == "1":
|
||||
print("The bear eats your face off. Good job!")
|
||||
elif bear == "2":
|
||||
print("The bear eats your legs off. Good job!")
|
||||
elif bear == "3":
|
||||
print("The bear eats your arms off. Good job!")
|
||||
else:
|
||||
print(f"Well, doing {bear} is probably better.")
|
||||
print("Bear runs away.")
|
||||
|
||||
elif door == "2":
|
||||
print("You stare into the endless abyss at Cthulhu's retina.")
|
||||
print("1. Blueberries.")
|
||||
print("2. Yellow jacket clothespins.")
|
||||
print("3. Understanding revolvers yelling melodies.")
|
||||
|
||||
insanity = input("> ")
|
||||
|
||||
if insanity == "1" or insanity == "2":
|
||||
print("Your body survives powered by a mind of jello.")
|
||||
print("Good job!")
|
||||
else:
|
||||
print("The insanity rots your eyes into a pool of muck.")
|
||||
print("Good job!")
|
||||
|
||||
else:
|
||||
print("You stumble around and fall on a knife and die. Good job!")
|
32
youngjin.han/python-the-hard-way/ex32.py
Normal file
32
youngjin.han/python-the-hard-way/ex32.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
the_count = [1, 2, 3, 4, 5]
|
||||
fruits = ['apples', 'oranges', 'pears', 'apricots']
|
||||
change = [1, 'pennies', 2, 'dimes', 3, 'quarters']
|
||||
|
||||
# this first kind of for-loop goes through a list
|
||||
for number in the_count:
|
||||
print(f"This is count {number}")
|
||||
|
||||
# same as above
|
||||
for fruit in fruits:
|
||||
print(f"A fruit of type: {fruit}")
|
||||
|
||||
# also we can go through mixed lists too
|
||||
for i in change:
|
||||
print(f"I got {i}")
|
||||
|
||||
# we can also build lists, first start with an empty one
|
||||
elements = []
|
||||
|
||||
# then use the range function to do 0 to 5 counts
|
||||
for i in range(0, 6):
|
||||
print(f"Adding {i} to the list.")
|
||||
# append is a function that lists understand
|
||||
elements.append(i)
|
||||
|
||||
elements = list(range(0, 6))
|
||||
|
||||
print(f"{elements}")
|
||||
|
||||
# now we can print them out too
|
||||
for i in elements:
|
||||
print(f"Element was: {i}")
|
44
youngjin.han/python-the-hard-way/ex33.py
Normal file
44
youngjin.han/python-the-hard-way/ex33.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
from sys import argv
|
||||
|
||||
script, a_iteration, a_increment = argv
|
||||
|
||||
#i = 0
|
||||
g_numbers = []
|
||||
|
||||
def while_loop(p_iteration, p_increment):
|
||||
l_i = 0
|
||||
l_numbers = []
|
||||
while l_i < p_iteration:
|
||||
print(f"At the top i is {l_i}")
|
||||
l_numbers.append(l_i)
|
||||
|
||||
l_i += p_increment
|
||||
print("Numbers now: ", l_numbers)
|
||||
print(f"At the bottom i is {l_i}")
|
||||
return l_numbers
|
||||
|
||||
def for_loop(p_iteration, p_increment):
|
||||
l_numbers = []
|
||||
for l_i in range(0, p_iteration, p_increment):
|
||||
print(f"At the top i is {l_i}")
|
||||
l_numbers.append(l_i)
|
||||
|
||||
print("Numbers now: ", l_numbers)
|
||||
print(f"At the bottom i is {l_i}")
|
||||
return l_numbers
|
||||
|
||||
g_numbers = while_loop(int(a_iteration), int(a_increment))
|
||||
|
||||
print("The numbers: ")
|
||||
|
||||
for num in g_numbers:
|
||||
print(num)
|
||||
|
||||
print("=====================================")
|
||||
|
||||
g_numbers = for_loop(int(a_iteration), int(a_increment))
|
||||
|
||||
print("The numbers: ")
|
||||
|
||||
for num in g_numbers:
|
||||
print(num)
|
89
youngjin.han/python-the-hard-way/ex35.py
Normal file
89
youngjin.han/python-the-hard-way/ex35.py
Normal file
|
@ -0,0 +1,89 @@
|
|||
from sys import exit
|
||||
|
||||
def gold_room():
|
||||
print("This room is full of gold. How much do you take?")
|
||||
|
||||
choice = int(input("> "))
|
||||
if 0 == choice or 1 == choice:
|
||||
if choice < 50:
|
||||
print("Nice, you're not greedy, you win!")
|
||||
exit(0)
|
||||
else:
|
||||
dead("You greedy bastard!")
|
||||
else:
|
||||
dead("Man, learn to type a number.")
|
||||
|
||||
# if "0" in choice or "1" in choice:
|
||||
# how_much = int(choice)
|
||||
# else:
|
||||
# dead("Man, learn to type a number.")
|
||||
# exit(0)
|
||||
|
||||
|
||||
# if how_much < 50:
|
||||
# print("Nice, you're not greedy, you win!")
|
||||
# exit(0)
|
||||
# else:
|
||||
# dead("You greedy bastard!")
|
||||
# exit(0)
|
||||
|
||||
|
||||
def bear_room():
|
||||
print("There is a bear here.")
|
||||
print("The bear has a bunch of honey.")
|
||||
print("The fat bear is in front of another door.")
|
||||
print("How are you going to move the bear?")
|
||||
bear_moved = False
|
||||
|
||||
while True:
|
||||
choice = input("> ")
|
||||
|
||||
if choice == "take honey":
|
||||
dead("The bear looks at you then slaps your face off.")
|
||||
elif choice == "taunt bear" and not bear_moved:
|
||||
print("The bear has moved from the door.")
|
||||
print("You can go through it now.")
|
||||
bear_moved = True
|
||||
elif choice == "taunt bear" and bear_moved:
|
||||
dead("The bear gets pissed off and chews your leg off.")
|
||||
elif choice == "open door" and bear_moved:
|
||||
gold_room()
|
||||
else:
|
||||
print("I got no idea what that means.")
|
||||
|
||||
|
||||
def cthulhu_room():
|
||||
print("Here you see the great evil Cthulhu.")
|
||||
print("He, it, whatever stares at you and you go insane.")
|
||||
print("Do you flee for your life or eat your head?")
|
||||
|
||||
choice = input("> ")
|
||||
|
||||
if "flee" in choice:
|
||||
start()
|
||||
elif "head" in choice:
|
||||
dead("Well that was tasty!")
|
||||
else:
|
||||
cthulhu_room()
|
||||
|
||||
|
||||
def dead(why):
|
||||
print(why, "Good job!")
|
||||
exit(0)
|
||||
|
||||
def start():
|
||||
print("You are in a dark room.")
|
||||
print("There is a door to your right and left.")
|
||||
print("Which one do you take?")
|
||||
|
||||
choice = input("> ")
|
||||
|
||||
if choice == "left":
|
||||
bear_room()
|
||||
elif choice == "right":
|
||||
cthulhu_room()
|
||||
else:
|
||||
dead("You stumble around the room until you starve.")
|
||||
|
||||
|
||||
start()
|
29
youngjin.han/python-the-hard-way/ex36.py
Normal file
29
youngjin.han/python-the-hard-way/ex36.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
from sys import exit
|
||||
|
||||
def front_room():
|
||||
while True:
|
||||
print("Up or Down")
|
||||
choice = input("> ")
|
||||
|
||||
if choice == "Up" or choice == "up" or choice == "UP" or choice == "U" or choice == "u":
|
||||
print("You will go to heaven.")
|
||||
exit(0)
|
||||
elif choice == "Down" or choice == "down" or choice == "DOWN" or choice == "D" or choice == "d":
|
||||
print("You will go to hell.")
|
||||
exit(0)
|
||||
else:
|
||||
print("You will be alive. but ......again......")
|
||||
|
||||
|
||||
def start():
|
||||
print("Front or Rear")
|
||||
|
||||
choice = input("> ")
|
||||
|
||||
if choice == "front" or choice == "Front" or choice == "F" or choice == "f" or choice == "FRONT":
|
||||
front_room()
|
||||
else:
|
||||
print("You stumble around the room until you starve.")
|
||||
|
||||
|
||||
start()
|
98
youngjin.han/python-the-hard-way/exercise26.txt
Normal file
98
youngjin.han/python-the-hard-way/exercise26.txt
Normal file
|
@ -0,0 +1,98 @@
|
|||
print("How old are you?", end=' ')
|
||||
age = input()
|
||||
print("How tall are you?", end=' ')
|
||||
print("How much do you weigh?", end=' '
|
||||
weight = input()
|
||||
|
||||
print(f"So, you're {age} old, {height} tall and {weight} heavy.")
|
||||
|
||||
script, filename = argv
|
||||
|
||||
txt = open(filenme)
|
||||
|
||||
print("Here's your file {filename}:")
|
||||
print(tx.read())
|
||||
|
||||
print("Type the filename again:")
|
||||
file_again = input("> ")
|
||||
|
||||
txt_again = open(file_again)
|
||||
|
||||
print(txt_again_read())
|
||||
|
||||
|
||||
print('Let's practice everything.')
|
||||
print('You\'d need to know \'bout escapes
|
||||
with \\ that do \n newlines and \t tabs.')
|
||||
|
||||
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 -
|
||||
print(f"This should be five: {five}"
|
||||
|
||||
def secret_formula(started)
|
||||
jelly_beans = started * 500
|
||||
jars = jelly_beans / 1000
|
||||
crates = jars 100
|
||||
return jelly_beans, jars, crates
|
||||
|
||||
|
||||
start_point = 10000
|
||||
beans, jars = secret_formula(start_point)
|
||||
|
||||
# remember that this is another way to format a string
|
||||
print("With a starting point of: {}".format(start_point))
|
||||
# it's just like with an f"" string
|
||||
print(f"We'd have {beans} beans, {jars} jars, and {crates} crates.")
|
||||
|
||||
start_point = start_point / 10
|
||||
|
||||
print("We can also do that this way:")
|
||||
formula = secret_formula(startpoint)
|
||||
# this is an easy way to apply a list to a format string
|
||||
print("We'd have {} beans, {} jars, and {} crates.".format(*formula))
|
||||
|
||||
|
||||
|
||||
people = 20
|
||||
cates = 30
|
||||
dogs = 15
|
||||
|
||||
|
||||
if people < cats:
|
||||
print "Too many cats! The world is doomed!"
|
||||
|
||||
if people < cats:
|
||||
print("Not many cats! The world is saved!")
|
||||
|
||||
if people < dogs:
|
||||
print("The world is drooled on!")
|
||||
|
||||
if people > dogs
|
||||
print("The world is dry!")
|
||||
|
||||
|
||||
dogs += 5
|
||||
|
||||
if people >= dogs:
|
||||
print("People are greater than or equal to dogs.")
|
||||
|
||||
if people <= dogs
|
||||
print("People are less than or equal to dogs.)
|
||||
|
||||
|
||||
if people = dogs:
|
||||
print("People are dogs.")
|
||||
|
97
youngjin.han/python-the-hard-way/languages.txt
Normal file
97
youngjin.han/python-the-hard-way/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
|
||||
文言
|
||||
吴语
|
||||
ייִדיש
|
||||
中文
|
|
@ -1,3 +1,38 @@
|
|||
* 2020-05-29
|
||||
- ex32.py
|
||||
- remove, insert, index, append, '+' and del
|
||||
- ex33.py
|
||||
- none
|
||||
- ex34.py
|
||||
- none
|
||||
- ex35.py
|
||||
- none
|
||||
- ex36.py
|
||||
- none
|
||||
* 2020-05-27
|
||||
** note
|
||||
- ex27.py
|
||||
- none
|
||||
- ex28.py
|
||||
- <= (greater than or equal to), =< (less than or equal t0)
|
||||
- ex29.py
|
||||
- The 'if' means to test criteria.
|
||||
- The 'if' processes the script is intended.
|
||||
- If the script is not indented, an error should be occured.
|
||||
- ex30.py
|
||||
- none
|
||||
- ex31.py
|
||||
- none
|
||||
* 2020-05-25
|
||||
** note
|
||||
- ex23.py
|
||||
- none
|
||||
- ex24.py
|
||||
- none
|
||||
- ex25.py
|
||||
- none
|
||||
- ex26.py
|
||||
- none
|
||||
* 2020-05-22
|
||||
** note
|
||||
- ex15.py
|
||||
|
|
Loading…
Reference in a new issue