From 78211363b9eceb662a98a5f7c982e752a073d89a Mon Sep 17 00:00:00 2001 From: samuel Date: Fri, 29 May 2020 17:00:06 +0200 Subject: [PATCH 1/7] up ex.35 --- sami/learn-python-the-hard-way/ex16.py | 6 +- sami/learn-python-the-hard-way/ex32.py | 34 ++++++++++ sami/learn-python-the-hard-way/ex33.py | 19 ++++++ sami/learn-python-the-hard-way/ex35.py | 90 +++++++++++++++++++++++++ sami/learn-python-the-hard-way/test.txt | 3 + 5 files changed, 147 insertions(+), 5 deletions(-) create mode 100644 sami/learn-python-the-hard-way/ex32.py create mode 100644 sami/learn-python-the-hard-way/ex33.py create mode 100644 sami/learn-python-the-hard-way/ex35.py create mode 100644 sami/learn-python-the-hard-way/test.txt diff --git a/sami/learn-python-the-hard-way/ex16.py b/sami/learn-python-the-hard-way/ex16.py index e8a2389..a1aab2f 100644 --- a/sami/learn-python-the-hard-way/ex16.py +++ b/sami/learn-python-the-hard-way/ex16.py @@ -8,17 +8,14 @@ print(f"We're going to erase {filename}.") print("If you don't want that, hit CTRL-C (^C).") print("If you do want that, hit RETURN.") - input("?") print("Opening the file...") target = open(filename, 'w') -print("Truncating the file. +print("Truncating the file. Goodbye!") target.truncate() -Goodbye!") - print("Now I'm going to ask you for three lines.") @@ -37,5 +34,4 @@ target.write(line3) target.write("\n") print("And finally, we close it.") - target.close() diff --git a/sami/learn-python-the-hard-way/ex32.py b/sami/learn-python-the-hard-way/ex32.py new file mode 100644 index 0000000..9e9ab6a --- /dev/null +++ b/sami/learn-python-the-hard-way/ex32.py @@ -0,0 +1,34 @@ +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 listLOOPS AND LISTS +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) + +# now we can print them out too +for i in elements: + print(f"Element was: {i}") diff --git a/sami/learn-python-the-hard-way/ex33.py b/sami/learn-python-the-hard-way/ex33.py new file mode 100644 index 0000000..edb81d5 --- /dev/null +++ b/sami/learn-python-the-hard-way/ex33.py @@ -0,0 +1,19 @@ +i = 0 +numbers = [] + +while i < 6: + print(f"At the top i is {i}") + numbers.append(i) + + i = i + 1 + print("Numbers now: ", numbers) + print(f"At the bottom i is {i}") + + + + +print("The numbers: ") + + +for num in numbers: + print(num) diff --git a/sami/learn-python-the-hard-way/ex35.py b/sami/learn-python-the-hard-way/ex35.py new file mode 100644 index 0000000..ede842f --- /dev/null +++ b/sami/learn-python-the-hard-way/ex35.py @@ -0,0 +1,90 @@ +from sys import exit + +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 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() diff --git a/sami/learn-python-the-hard-way/test.txt b/sami/learn-python-the-hard-way/test.txt new file mode 100644 index 0000000..b28b04f --- /dev/null +++ b/sami/learn-python-the-hard-way/test.txt @@ -0,0 +1,3 @@ + + + From 7f67a6bd5c5a8371654f22f7bf85f41634a585c3 Mon Sep 17 00:00:00 2001 From: samuel Date: Mon, 1 Jun 2020 16:58:46 +0200 Subject: [PATCH 2/7] two calc.py for combination --- sami/learn-python-the-hard-way/calc.py | 17 +++++++++++++++++ sami/learn-python-the-hard-way/calc2.py | 13 +++++++++++++ sami/learn-python-the-hard-way/output.txt | 0 3 files changed, 30 insertions(+) create mode 100644 sami/learn-python-the-hard-way/calc.py create mode 100644 sami/learn-python-the-hard-way/calc2.py create mode 100644 sami/learn-python-the-hard-way/output.txt diff --git a/sami/learn-python-the-hard-way/calc.py b/sami/learn-python-the-hard-way/calc.py new file mode 100644 index 0000000..51c8b18 --- /dev/null +++ b/sami/learn-python-the-hard-way/calc.py @@ -0,0 +1,17 @@ +# This function adds two numbers +def add(num1, num2): + return num1 + num2 +file = open("output.txt","a") +file.write(f's +# Take input from the user +select = int(input("Select operations form 1, 2, 3, 4 :")) + +number_1 = int(input("Enter first number: ")) +number_2 = int(input("Enter second number: ")) + + +print(number_1, "+", number_2, "=", + add(number_1, number_2)) + + + diff --git a/sami/learn-python-the-hard-way/calc2.py b/sami/learn-python-the-hard-way/calc2.py new file mode 100644 index 0000000..c9fe520 --- /dev/null +++ b/sami/learn-python-the-hard-way/calc2.py @@ -0,0 +1,13 @@ +def add(a,b): +# calculating the sum + sum=a+b + #opening the file in an append mode + file = open('output.txt',"a") + file.write(f'Sum of {a} and {b} is {sum}\n') + #at last i close the file + file.close() + + +#call the function +add(5,7) +add(2,6) diff --git a/sami/learn-python-the-hard-way/output.txt b/sami/learn-python-the-hard-way/output.txt new file mode 100644 index 0000000..e69de29 From 366d21603538a58aa9017018619b0c0e477c0787 Mon Sep 17 00:00:00 2001 From: samuel Date: Fri, 12 Jun 2020 17:08:16 +0200 Subject: [PATCH 3/7] tried to solve ex42.py --- sami/learn-python-the-hard-way/ex42.py | 89 ++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 sami/learn-python-the-hard-way/ex42.py diff --git a/sami/learn-python-the-hard-way/ex42.py b/sami/learn-python-the-hard-way/ex42.py new file mode 100644 index 0000000..9dc58f2 --- /dev/null +++ b/sami/learn-python-the-hard-way/ex42.py @@ -0,0 +1,89 @@ + ## Animal is-a object (yes, sort of confusing) look at the extra credit + class Animal(object): + + pass + + ## dog has an attribute + class Dog(Animal): + + + def __init__(self, name): + ## ?? + + self.name + + +## +class Cat(Animal): + + + def __init__(self, name): + ## ?? + self.name = name + +## ?? +class Person(object): + + + def __init__(self, name): + ## ?? + self.name = name + + + ## Person has-a pet of some kind194 + + self.pet = None + + +## ?? +class Employee(Person): + + + def __init__(self, name, salary): + ## ?? hmm what is this strange magic? + super(Employee, self).__init__(name) + ## ?? + self.salary = salary + +## ?? +class Fish(object): + + pass + +## ?? +class Salmon(Fish): + + pass + +## ?? +class Halibut(Fish): + + pass + +## rover is-a Dog +rover = Dog("Rover") + +## ?? +satan = Cat("Satan") + +## ?? +mary = Person("Mary") + +## ?? +mary.pet = satan + +## ?? +frank = Employee("Frank", 120000) + +## ?? +frank.pet = rover + +## ?? +flipper = Fish() + +## ?? +crouse = Salmon() + + +## ?? + harry = Halibut() From 53232c986937eca8da8ab70f6fa9bec118f19a12 Mon Sep 17 00:00:00 2001 From: samuel Date: Mon, 15 Jun 2020 16:58:47 +0200 Subject: [PATCH 4/7] ex.43 classes --- sami/learn-python-the-hard-way/ex43.py | 115 ++++++++++++++++++ .../learn-python-the-hard-way/ex43_classes.py | 66 ++++++++++ 2 files changed, 181 insertions(+) create mode 100644 sami/learn-python-the-hard-way/ex43.py create mode 100644 sami/learn-python-the-hard-way/ex43_classes.py diff --git a/sami/learn-python-the-hard-way/ex43.py b/sami/learn-python-the-hard-way/ex43.py new file mode 100644 index 0000000..b6eff94 --- /dev/null +++ b/sami/learn-python-the-hard-way/ex43.py @@ -0,0 +1,115 @@ +class Scene(object): + + def enter(self): + print("This scene is not yet configured.") + print("Subclass it and implement enter().") + exit(1) + + + +class Engine(object): + def __init__(self, scene_map): + self.scene_map = scene_map + + + def play(self): + current_scene = self.scene_map.opening_scene() + last_scene = self.scene_map.next_scene('finished') + + while current_scene != last_scene: + next_scene_name = current_scene.enter() + current_scene = self.scene_map.next_scene(next_scene_name) + + # be sure to print out the last scene + current_scene.enter() + + +class Death(Scene): + + + quips = [ + "You died. + You kinda suck at this.", + "Your Mom would be proud...if she were smarter.", + "Such a luser.", + "I have a small puppy that's better at this.", + "You're worse than your Dad's jokes." + + +] + + + def enter(self): + print(Death.quips[randint(0, len(self.quips)-1)]) + exit(1) + +class CentralCorridor(Scene): + + def enter(self): + print(dedent(""" + The Gothons of Planet Percal #25 have invaded your ship and + destroyed your entire crew. + member and your last mission is to get the neutron destruct + bomb from the Weapons Armory, put it in the bridge, and + blow the ship up after getting into an escape pod. + You are the last surviving + + You're running down the central corridor to the Weapons + Armory when a Gothon jumps out, red scaly skin, dark grimy + teeth, and evil clown costume flowing around his hate + filled body. He's blocking the door to the Armory and about to pull a weapon to blast you. + """)) + + action = input("> ") + + + + if action == "shoot!": + print(dedent(""" + Quick on the draw you yank out your blaster and fire + it at the Gothon. + moving around his body, which throws off your aim. + Your laser hits his costume but misses him entirely. + This completely ruins his brand new costume his mother + bought him, which makes him fly into an insane rage + and blast you repeatedly in the face until you are + dead. + """)) + + + return 'death' + + elif action == "dodge!": + print(dedent(""" + + Like a world class boxer you dodge, weave, slip and + slide right as the Gothon's blaster cranks a laser + past your head. + your foot slips and you bang your head on the metal + wall and pass out. + die as the Gothon stomps on your head and eats you. + You wake up shortly after only to + """)) + + return 'death' + + + + elif action == "tell a joke": + print(dedent(""" + Lucky for you they made you learn Gothon insults in + the academy. + Lbhe zbgure vf fb sng, jura fur fvgf nebhaq gur ubhfr, + fur fvgf nebhaq gur ubhfr. + not to laugh, then busts out laughing and can't move. + While he's laughing you run up and shoot him square in + the head putting him down, then jump through the + Weapon Armory door. + """)) + +return 'laser_weapon_armory' + + +else: + print("DOES NOT COMPUTE!") + return 'central_corridor' diff --git a/sami/learn-python-the-hard-way/ex43_classes.py b/sami/learn-python-the-hard-way/ex43_classes.py new file mode 100644 index 0000000..44e2382 --- /dev/null +++ b/sami/learn-python-the-hard-way/ex43_classes.py @@ -0,0 +1,66 @@ + +class Scene(object): + + def enter(self): + pass + + + +class Engine(object): + + def __init__(self, scene_map): + pass + + def play(self): + pass + + +class Death(Scene): + + def enter(self): + pass + + +class CentralCorridor(Scene): + + def enter(self): + pass + + +class LaserWeaponArmory(Scene): + + def enter(self): + pass + + +class TheBridge(Scene): + + def enter(self): + pass + + +class EscapePod(Scene): + +def enter(self) + pass + + + +class Map(object): + + + + def __init__(self, start_scene): + pass + + + def next_scene(self, scene_name): + pass + + def opening_scene(self): + pass + + +a_map = Map('central_corridor') +a_game = Engine(a_map) +a_game.play() From b48dccca847f45cd2a3c26b4369f2b6b8df1d56d Mon Sep 17 00:00:00 2001 From: Samuel Hailu Date: Fri, 19 Jun 2020 16:44:48 +0200 Subject: [PATCH 5/7] game idea --- sami/learn-python-the-hard-way/learn-german.org | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 sami/learn-python-the-hard-way/learn-german.org diff --git a/sami/learn-python-the-hard-way/learn-german.org b/sami/learn-python-the-hard-way/learn-german.org new file mode 100644 index 0000000..ef55b89 --- /dev/null +++ b/sami/learn-python-the-hard-way/learn-german.org @@ -0,0 +1,9 @@ +* Ger man +** This game can be a quiz about the trennbaren verben since the german language is very vast I can start with a specfic topic that would the phrasal-verb which are really confusing in the German verbs + *** The quiz is simply player gets a trennenbaren verb and choices and then chooses the best answer +**** Every time a player gets the correct, player answer gets a point. + + +* Prepositions +** This game can be about prepositions + *** The quiz is gets verb and choices and then chooses the best answer. From 9c213de08da454297d93961084199a4cc6e95620 Mon Sep 17 00:00:00 2001 From: samuel Date: Wed, 24 Jun 2020 16:41:27 +0200 Subject: [PATCH 6/7] wrote the fist code of the quiz --- .../__pycache__/Question.cpython-37.pyc | Bin 0 -> 1029 bytes .../learn-german.org | 15 ++++++++++++ sami/learn-python-the-hard-way/quiz.py | 23 ++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 sami/learn-python-the-hard-way/__pycache__/Question.cpython-37.pyc create mode 100644 sami/learn-python-the-hard-way/quiz.py diff --git a/sami/learn-python-the-hard-way/__pycache__/Question.cpython-37.pyc b/sami/learn-python-the-hard-way/__pycache__/Question.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..059710a19630659426551c8f2d765e71fa2fe683 GIT binary patch literal 1029 zcmb7DL2uJA6tL$n?vc53jzd_cAEqoCRKvSi`_OXu`}CQX_cP3Kf@p3 z$N0)=XHIb9y>x|%8?OBF`PuJ#etuuy937;)nbhqq)J%1{PdN{L86knGVN z@RE%B8#S`IsxalqL&(WMwro7;doUuf)Xg`E@#3=vq!Juggg#xlyH>kBhRX z9{R@3$}O}SyM-JtxDn$eUrqM)JZn}y$@5Z`F3*wQB0r%qU7!3pv)@0@B0Q{kE%V%` zd0uPLR)~jre%ZKO~3o?c`B^v)-y zRnX*eeFFLH5DcLaP5a-F8vF}@KKhpW<2_TpQ?fM})Sr1ki%()u7e0BhQ_@Q;$UX)$ Pq>tl(#?g=-he`4q;yC(c literal 0 HcmV?d00001 diff --git a/sami/learn-python-the-hard-way/learn-german.org b/sami/learn-python-the-hard-way/learn-german.org index ef55b89..6a47b3c 100644 --- a/sami/learn-python-the-hard-way/learn-german.org +++ b/sami/learn-python-the-hard-way/learn-german.org @@ -7,3 +7,18 @@ * Prepositions ** This game can be about prepositions *** The quiz is gets verb and choices and then chooses the best answer. + +- My Game Description +- I want to program a translation Quiz +- Game flow is: + - The Quiz shows a german word + - It prompts for a translation + - The player enters the translation + - Quiz compares + - The Quiz outputs write or wrong + - The Quiz Counts your points + - For a correct answer player get plus 5 points + - For incorrect answer player gets minus 3 points + - The Quiz ends when player types quit + - When you quit the Quiz shows the total points + - ( optional) The Quiz shows total amount of write and wrong answers diff --git a/sami/learn-python-the-hard-way/quiz.py b/sami/learn-python-the-hard-way/quiz.py new file mode 100644 index 0000000..cc40132 --- /dev/null +++ b/sami/learn-python-the-hard-way/quiz.py @@ -0,0 +1,23 @@ +class Question: + def __init__(self, prompt, answer): + self.prompt = prompt + self.answer = answer + +question_prompts = [ + "Which word does not much with the German verb aufsatzen?\n(a) to put on\n(b) to set up\n(c) to sit up\n(d) to stop", + "which word does not much with the German verb absagen?\n(a) to cancel\n(b) to refuse\n(c) to decline\n(d) to approve", +] + +questions = [ + Question(question_prompts[0], "d"), + Question(question_prompts[1], "d"), +] + +def run_quiz(questions): + score = 0 + for question in questions: + answer = input(question.prompt) + if answer == question.answer: + score += 1 + print("you got", score, "out of", len(questions)) +run_quiz(questions) From 38839f5d3bf04fb79198be5ca438bc11a4cc62d1 Mon Sep 17 00:00:00 2001 From: samuel Date: Thu, 25 Jun 2020 15:46:41 +0200 Subject: [PATCH 7/7] added quiz.py more codes --- sami/learn-python-the-hard-way/.#quiz2.py | 1 + .../learn-german.org | 8 ++++ sami/learn-python-the-hard-way/quiz.py | 38 +++++++++++++++++-- sami/learn-python-the-hard-way/quiz2.py | 16 ++++++++ 4 files changed, 59 insertions(+), 4 deletions(-) create mode 120000 sami/learn-python-the-hard-way/.#quiz2.py create mode 100644 sami/learn-python-the-hard-way/quiz2.py diff --git a/sami/learn-python-the-hard-way/.#quiz2.py b/sami/learn-python-the-hard-way/.#quiz2.py new file mode 120000 index 0000000..d7a8c4f --- /dev/null +++ b/sami/learn-python-the-hard-way/.#quiz2.py @@ -0,0 +1 @@ +sami@afro-linux-lenovo-b50-30.18673:1593006374 \ No newline at end of file diff --git a/sami/learn-python-the-hard-way/learn-german.org b/sami/learn-python-the-hard-way/learn-german.org index 6a47b3c..0c686f7 100644 --- a/sami/learn-python-the-hard-way/learn-german.org +++ b/sami/learn-python-the-hard-way/learn-german.org @@ -22,3 +22,11 @@ - The Quiz ends when player types quit - When you quit the Quiz shows the total points - ( optional) The Quiz shows total amount of write and wrong answers +* Final stage +# Final stage +if score <= 1: + print("Your total score is:", score, "- You suck!") +elif score == 2: + print("Your total score is:", score, "- You went ok!") +else + print("Your total score is:", score, "- You are awesome!") diff --git a/sami/learn-python-the-hard-way/quiz.py b/sami/learn-python-the-hard-way/quiz.py index cc40132..de9505e 100644 --- a/sami/learn-python-the-hard-way/quiz.py +++ b/sami/learn-python-the-hard-way/quiz.py @@ -4,13 +4,29 @@ class Question: self.answer = answer question_prompts = [ - "Which word does not much with the German verb aufsatzen?\n(a) to put on\n(b) to set up\n(c) to sit up\n(d) to stop", - "which word does not much with the German verb absagen?\n(a) to cancel\n(b) to refuse\n(c) to decline\n(d) to approve", + "Which word does not match with the German verb aufsetzen? \n(a) to put on \n(b) to set up \n(c) to sit up \n(d) to stop \nAnswer: ", + "which word does not match with the German verb absagen? \n(a) to cancel \n(b) to refuse \n(c) to decline \n(d) to approve \nAnswer: ", + "Which word does not match with the German verb umsteigen? \n(a) to transfer \n(b) to change \n(c) to stay \n(d) to switch \nAnswer: ", + "Which word does not match with the German verb abbiegen? \n(a) to return \n(b) to to bend \n(c) to turn off \n(d) to turn\nAnswer: ", + "Which word does not match with the German verb anbieten? \n(a) to offer \n(b) to demand \n(c) to proffer \n(d) volunteer \nAnswer: ", + "Which word does not match with the German verb beitragen? \n(a) to obligate \n(b) to redound \n(c) to help \n(d) contribute \nAnswer: ", + "Which word does not match with the German verb weiterleiten? \n(a) to forward \n(b) to send \n(c) to pass on\n(d) to replace \nAnswer: ", + "Which word does not match with the German verb abziehen? \n(a) to remove \n(b) to deduct \n(c) to top up \n(d) pull off \nAnswer: ", + "Which word does not match with the German verb anpassen? \n(a) to adjust \n(b) to repair \n(c) to customize \n(d) to adapt \nAnswer: ", + "Which word does not match with the German verb umsetzen? \n(a) to destroy \n(b) to implement \n(c) to translate \n(d) to convert \nAnswer: ", ] questions = [ Question(question_prompts[0], "d"), Question(question_prompts[1], "d"), + Question(question_prompts[2], "c"), + Question(question_prompts[3], "a"), + Question(question_prompts[4], "b"), + Question(question_prompts[5], "a"), + Question(question_prompts[6], "d"), + Question(question_prompts[7], "c"), + Question(question_prompts[8], "b"), + Question(question_prompts[9], "a"), ] def run_quiz(questions): @@ -18,6 +34,20 @@ def run_quiz(questions): for question in questions: answer = input(question.prompt) if answer == question.answer: - score += 1 - print("you got", score, "out of", len(questions)) + score += 5 + print("Correct! Your score is", score,) + + else: + print("Incorrect!") + score -= 3 + print("You lost 3 points!") + print ("Score: ", score) + print ("\n") + + + + + + + run_quiz(questions) diff --git a/sami/learn-python-the-hard-way/quiz2.py b/sami/learn-python-the-hard-way/quiz2.py new file mode 100644 index 0000000..ad92438 --- /dev/null +++ b/sami/learn-python-the-hard-way/quiz2.py @@ -0,0 +1,16 @@ +score = 0 + +# QUESTION 1 +input ("Which verb does not match with the German verb aufsetzen? \n(a) to put on \n(b) to set up \n(c) to sit up \n(d) to stop \nAnswer: + +if answer1 == "d" or answer1 == "to stop": + score += 5 + print ("Correct!") + print ("Score: ", score) + print ("\n") +else: + print("Incorrect! The answer is choice (d) or to stop) + score -= 3 + print("You lost 3 points!") + print ("Score: ", score) + print ("\n")