Merge remote-tracking branch 'youngjin/master'
This commit is contained in:
commit
36f6413778
6 changed files with 213 additions and 0 deletions
|
@ -1,3 +1,11 @@
|
|||
* 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
|
||||
|
|
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()
|
|
@ -1,3 +1,14 @@
|
|||
* 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
|
||||
|
|
Loading…
Reference in a new issue