Merge remote-tracking branch 'sami/master'
This commit is contained in:
commit
1148f37aaa
16 changed files with 549 additions and 5 deletions
1
sami/learn-python-the-hard-way/.#quiz2.py
Symbolic link
1
sami/learn-python-the-hard-way/.#quiz2.py
Symbolic link
|
@ -0,0 +1 @@
|
|||
sami@afro-linux-lenovo-b50-30.18673:1593006374
|
Binary file not shown.
17
sami/learn-python-the-hard-way/calc.py
Normal file
17
sami/learn-python-the-hard-way/calc.py
Normal file
|
@ -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))
|
||||
|
||||
|
||||
|
13
sami/learn-python-the-hard-way/calc2.py
Normal file
13
sami/learn-python-the-hard-way/calc2.py
Normal file
|
@ -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)
|
|
@ -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()
|
||||
|
|
34
sami/learn-python-the-hard-way/ex32.py
Normal file
34
sami/learn-python-the-hard-way/ex32.py
Normal file
|
@ -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}")
|
19
sami/learn-python-the-hard-way/ex33.py
Normal file
19
sami/learn-python-the-hard-way/ex33.py
Normal file
|
@ -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)
|
90
sami/learn-python-the-hard-way/ex35.py
Normal file
90
sami/learn-python-the-hard-way/ex35.py
Normal file
|
@ -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()
|
89
sami/learn-python-the-hard-way/ex42.py
Normal file
89
sami/learn-python-the-hard-way/ex42.py
Normal file
|
@ -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()
|
115
sami/learn-python-the-hard-way/ex43.py
Normal file
115
sami/learn-python-the-hard-way/ex43.py
Normal file
|
@ -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'
|
66
sami/learn-python-the-hard-way/ex43_classes.py
Normal file
66
sami/learn-python-the-hard-way/ex43_classes.py
Normal file
|
@ -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()
|
32
sami/learn-python-the-hard-way/learn-german.org
Normal file
32
sami/learn-python-the-hard-way/learn-german.org
Normal file
|
@ -0,0 +1,32 @@
|
|||
* 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.
|
||||
|
||||
- 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
|
||||
* 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!")
|
0
sami/learn-python-the-hard-way/output.txt
Normal file
0
sami/learn-python-the-hard-way/output.txt
Normal file
53
sami/learn-python-the-hard-way/quiz.py
Normal file
53
sami/learn-python-the-hard-way/quiz.py
Normal file
|
@ -0,0 +1,53 @@
|
|||
class Question:
|
||||
def __init__(self, prompt, answer):
|
||||
self.prompt = prompt
|
||||
self.answer = answer
|
||||
|
||||
question_prompts = [
|
||||
"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):
|
||||
score = 0
|
||||
for question in questions:
|
||||
answer = input(question.prompt)
|
||||
if answer == question.answer:
|
||||
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)
|
16
sami/learn-python-the-hard-way/quiz2.py
Normal file
16
sami/learn-python-the-hard-way/quiz2.py
Normal file
|
@ -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")
|
3
sami/learn-python-the-hard-way/test.txt
Normal file
3
sami/learn-python-the-hard-way/test.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
|
||||
|
||||
|
Loading…
Reference in a new issue