@ -0,0 +1,54 @@ | |||
#!/usr/bin/env python3 | |||
#title :FA-3.py | |||
#description :Final Assignemt: NS-kaartautomaat | |||
#author :Marcel Haazen | |||
#email :marcel@haazen.xyz | |||
#date :04-11-2019 - 11:58 | |||
#edit_date :04-11-2019 - 11:58 | |||
#version :0.1 | |||
#usage :python3 FA-3.py | |||
#notes : | |||
#python_version :3.7.4 | |||
#============================================================================== | |||
import string | |||
stations = ["Schagen", "Heerhugowaard", "Alkmaar", "Castricum", "Zaandam", "Amsterdam Sloterdijk", "Amsterdam Centraal", "Amsterdam Amstel", "Utrecht Centraal", "'s-Hertogenbosch", "Eindhoven", "Weert", "Roermond", "Sittard", "Maastricht"] | |||
def inlezen_beginstation(stations): | |||
while True: | |||
start = string.capwords(str(input("What is your starting station? "))) | |||
if start in stations: | |||
break | |||
else: | |||
print("\nThis train does not come in:", start, end= "." "\n") | |||
return start | |||
def inlezen_eindstation(stations,start): | |||
while True: | |||
ends = string.capwords(str(input("What is your starting station? "))) | |||
if ends in stations: | |||
if stations.index(ends) > stations.index(start): | |||
break | |||
else: | |||
print("\nThe endstation is before the current station\n") | |||
else: | |||
print("\nThis train does not come in:", ends, end= "." "\n") | |||
return ends | |||
def omroepen_reis(stations, beginstation, eindstation): | |||
stops = stations.index(eindstation) - stations.index(beginstation) | |||
print("\n \nHet beginstation", beginstation, "is het", (str(stations.index(beginstation)+ 1) + "e"), "station in het traject.") | |||
print("Het eindstation", eindstation, "is het", (str(stations.index(eindstation)+ 1) + "e"), "station in het traject.") | |||
print("De afstand bedraagt", stops, "stations(s).") | |||
print("De prijs van het kaartje is", 5 * stops, "euro.") | |||
print("\nJij stapt in de trein in:", beginstation) | |||
for i in range((stations.index(beginstation)), (stations.index(eindstation))): | |||
i += 1 | |||
if i != stations.index(eindstation): | |||
print(" -",stations[i]) | |||
print("Jij stapt uit in:", eindstation) | |||
beginstation = inlezen_beginstation(stations) | |||
eindstation = inlezen_eindstation(stations, beginstation) | |||
omroepen_reis(stations, beginstation, eindstation) |
@ -0,0 +1,25 @@ | |||
#!/usr/bin/env python3 | |||
#title :10-1.py | |||
#description :10.1: Catching exceptions | |||
#author :Marcel Haazen | |||
#email :marcel@haazen.xyz | |||
#date :07-11-2019 - 11:15 | |||
#edit_date :07-11-2019 - 11:45 | |||
#version :0.1 | |||
#usage :python3 10-1.py | |||
#notes : | |||
#python_version :3.7.4 | |||
#============================================================================== | |||
amount = 4356 | |||
try: | |||
devider = int(input("Door hoeveel wil je het delen? ")) | |||
assert devider > 0 | |||
print("Iedereen moet",amount/devider," euro betalen") | |||
except ZeroDivisionError: | |||
print("Delen door nul kan niet!") | |||
except ValueError: | |||
print("Gebruik cijfers voor het invoeren van het aantal!") | |||
except AssertionError: | |||
print("Negatieve getallen zijn niet toegestaan!") | |||
except: | |||
print("Onjuiste invoer!") |
@ -0,0 +1,23 @@ | |||
#!/usr/bin/env python3 | |||
#title :10-2.py | |||
#description :10.2: User input & exceptions | |||
#author :Marcel Haazen | |||
#email :marcel@haazen.xyz | |||
#date :07-11-2019 - 11:45 | |||
#edit_date :07-11-2019 - 11:54 | |||
#version :0.1 | |||
#usage :python3 10-2.py | |||
#notes : | |||
#python_version :3.7.4 | |||
#============================================================================== | |||
while True: | |||
try: | |||
uurloon = float(input("Wat is je uurloon?")) | |||
uren = float(input("Hoeveel uur heb je gewerkt?")) | |||
assert uren > 0 | |||
print("Je salaris is", uurloon*uren, "Euro") | |||
break | |||
except ValueError: | |||
print("Wij accepteren aleen cijfers geen andere characters") | |||
except AssertionError: | |||
print("Negatieve werk uren !? Wil je gaan betalen inplaats van betaald worden?") |
@ -0,0 +1,35 @@ | |||
#!/usr/bin/env python3 | |||
#title :10-2.py | |||
#description :10.2: User input & exceptions | |||
#author :Marcel Haazen | |||
#email :marcel@haazen.xyz | |||
#date :07-11-2019 - 11:45 | |||
#edit_date :07-11-2019 - 11:54 | |||
#version :0.1 | |||
#usage :python3 10-2.py | |||
#notes : | |||
#python_version :3.7.4 | |||
#============================================================================== | |||
while True: | |||
try: | |||
filename = input("Wat is de naam van het bestand? \n") | |||
assert filename != "" | |||
filename = filename+".txt" | |||
file = open(filename, "r") | |||
n = 0 | |||
i = 0 | |||
li = 0 | |||
for line in file: | |||
i = i+1 | |||
fields = line.split(",") | |||
if n < int(fields[0]): | |||
n = int(fields[0]) | |||
li = li+1 | |||
print("Deze file telt",i,"regels") | |||
print("Het grootste kaartnummer is:",n,"en dat staat op regel",li+1) | |||
file.close | |||
break | |||
except FileNotFoundError: | |||
print("Er is geen bestand gevonden met de naam", filename) | |||
except AssertionError: | |||
print("Je moet wel een bestands naam invullen he grapjas.") |
@ -0,0 +1,6 @@ | |||
325255, Jan Jansen | |||
334343, Erik Materus | |||
235434, Ali Ahson | |||
645345, Eva Versteeg | |||
534545, Jan de Wilde | |||
345355, Henk de Vries |
@ -0,0 +1,35 @@ | |||
#!/usr/bin/env python3 | |||
#title :11-1.py | |||
#description :11.1: Namespaces | |||
#author :Marcel Haazen | |||
#email :marcel@haazen.xyz | |||
#date :07-11-2019 - 12:55 | |||
#edit_date :07-11-2019 - 12:55 | |||
#version :0.1 | |||
#usage :python3 11-1.py | |||
#notes : | |||
#python_version :3.7.4 | |||
#============================================================================== | |||
import time | |||
b = 7 | |||
def verdubbelB(): | |||
return b + b | |||
dubbel = verdubbelB() | |||
print(dubbel) | |||
print(time.strftime(("%H:%M:%S"))) | |||
def f(y): | |||
return 2*y + 1 | |||
def g(x): | |||
return 5 + x + 10 | |||
print(f(3)+g(3)) |
@ -0,0 +1,29 @@ | |||
#!/usr/bin/env python3 | |||
#title :11-2.py | |||
#description :11.2: JSON-stationslijsten lezen | |||
#author :Marcel Haazen | |||
#email :marcel@haazen.xyz | |||
#date :07-11-2019 - 13:45 | |||
#edit_date :07-11-2019 - 14:05 | |||
#version :0.1 | |||
#usage :python3 11-2.py | |||
#notes : | |||
#python_version :3.7.4 | |||
#============================================================================== | |||
import json | |||
with open("stationslijst.json", "r") as json_file: | |||
data = json.load(json_file) | |||
lng = [] | |||
print("Dit zijn de namen, codes en types van de stations:") | |||
for station in data["payload"]: | |||
name = station["namen"]["lang"] | |||
code = station["code"] | |||
st = station["stationType"] | |||
lng.append(station['lng']) | |||
print("{:25} - {:5} : {:5}".format(name, code, st)) | |||
for station in data["payload"]: | |||
if station["lng"] == max(lng): | |||
print("\nHet meest oostelijke gelegen station is:", station["namen"]["lang"]) |
@ -0,0 +1,34 @@ | |||
#!/usr/bin/env python3 | |||
#title :11-3.py | |||
#description :11.3: JSON-files schrijven | |||
#author :Marcel Haazen | |||
#email :marcel@haazen.xyz | |||
#date :07-11-2019 - 14:05 | |||
#edit_date :07-11-2019 - 14:05 | |||
#version :0.1 | |||
#usage :python3 11-3.py | |||
#notes : | |||
#python_version :3.7.4 | |||
#============================================================================== | |||
import json | |||
import datetime | |||
bestand = "inlogger.json" | |||
time = datetime.datetime.today().strftime("%a %d %b %Y, %H:%M:%S,") | |||
while True: | |||
naam = input("Wat is je achternaam? ") | |||
if naam == "einde": | |||
break | |||
voorl = input("Wat zijn je voorletters? ") | |||
gbdatum = input("Wat is je geboortedatum? ") | |||
email = input("Wat is je e-mail adres? ") | |||
gdict = {"inlogtijd": time, "naam": naam, "voorletters":voorl,"geb_datum": gbdatum, "e-mail": email} | |||
with open(bestand) as json_bestand: | |||
data = json.load(json_bestand) | |||
with open(bestand, "w") as json_bestand: | |||
data.append(gdict) | |||
json.dump(data, json_bestand, indent = 4) |
@ -0,0 +1,205 @@ | |||
{ | |||
"links": {}, | |||
"payload": [{ | |||
"sporen": [], | |||
"synoniemen": [], | |||
"heeftFaciliteiten": true, | |||
"heeftVertrektijden": true, | |||
"heeftReisassistentie": false, | |||
"code": "STP", | |||
"namen": { | |||
"lang": "London St. Pancras Int.", | |||
"kort": "London StP", | |||
"middel": "London St. P Int" | |||
}, | |||
"stationType": "MEGA_STATION", | |||
"land": "GB", | |||
"UICCode": "7015400", | |||
"lat": 51.531437, | |||
"lng": -0.126136, | |||
"radius": 1, | |||
"naderenRadius": 1, | |||
"EVACode": "7004428" | |||
}, { | |||
"sporen": [], | |||
"synoniemen": [], | |||
"heeftFaciliteiten": true, | |||
"heeftVertrektijden": true, | |||
"heeftReisassistentie": false, | |||
"code": "MA", | |||
"namen": { | |||
"lang": "Augsburg Hbf", | |||
"kort": "Augsburg", | |||
"middel": "Augsburg Hbf" | |||
}, | |||
"stationType": "SNELTREIN_STATION", | |||
"land": "D", | |||
"UICCode": "8002140", | |||
"lat": 48.3654307143927, | |||
"lng": 10.88547706604, | |||
"radius": 1, | |||
"naderenRadius": 1, | |||
"EVACode": "8000013" | |||
}, { | |||
"sporen": [], | |||
"synoniemen": [], | |||
"heeftFaciliteiten": true, | |||
"heeftVertrektijden": true, | |||
"heeftReisassistentie": false, | |||
"code": "BHF", | |||
"namen": { | |||
"lang": "Berlin Ostbahnhof", | |||
"kort": "Berlin Ost", | |||
"middel": "Berlin Ostbhf" | |||
}, | |||
"stationType": "KNOOPPUNT_INTERCITY_STATION", | |||
"land": "D", | |||
"UICCode": "8003004", | |||
"lat": 52.5104989, | |||
"lng": 13.4346995, | |||
"radius": 1, | |||
"naderenRadius": 1, | |||
"EVACode": "8010255" | |||
}, { | |||
"sporen": [], | |||
"synoniemen": [], | |||
"heeftFaciliteiten": true, | |||
"heeftVertrektijden": true, | |||
"heeftReisassistentie": false, | |||
"code": "BSPD", | |||
"namen": { | |||
"lang": "Berlin-Spandau", | |||
"kort": "Berlin-Spa", | |||
"middel": "Berlin-Spandau" | |||
}, | |||
"stationType": "INTERCITY_STATION", | |||
"land": "D", | |||
"UICCode": "8003025", | |||
"lat": 52.5343152, | |||
"lng": 13.1989467, | |||
"radius": 1, | |||
"naderenRadius": 1, | |||
"EVACode": "8010404" | |||
}, { | |||
"sporen": [], | |||
"synoniemen": [], | |||
"heeftFaciliteiten": true, | |||
"heeftVertrektijden": true, | |||
"heeftReisassistentie": false, | |||
"code": "GSB", | |||
"namen": { | |||
"lang": "Berlin Gesundbrunnen", | |||
"kort": "Berlin Gsb", | |||
"middel": "Berlin Gesundbr." | |||
}, | |||
"stationType": "INTERCITY_STATION", | |||
"land": "D", | |||
"UICCode": "8007799", | |||
"lat": 52.5486327, | |||
"lng": 13.3904267, | |||
"radius": 1, | |||
"naderenRadius": 1, | |||
"EVACode": "8011102" | |||
}, { | |||
"sporen": [], | |||
"synoniemen": [], | |||
"heeftFaciliteiten": true, | |||
"heeftVertrektijden": true, | |||
"heeftReisassistentie": false, | |||
"code": "ESRT", | |||
"namen": { | |||
"lang": "Schwerte (Ruhr)", | |||
"kort": "Schwerte", | |||
"middel": "Schwerte (R)" | |||
}, | |||
"stationType": "STOPTREIN_STATION", | |||
"land": "D", | |||
"UICCode": "8008016", | |||
"lat": 51.442281, | |||
"lng": 7.55896, | |||
"radius": 1, | |||
"naderenRadius": 1, | |||
"EVACode": "8000037" | |||
}, { | |||
"sporen": [], | |||
"synoniemen": [], | |||
"heeftFaciliteiten": true, | |||
"heeftVertrektijden": true, | |||
"heeftReisassistentie": false, | |||
"code": "HAGEN", | |||
"namen": { | |||
"lang": "Hagen Hbf", | |||
"kort": "Hagen", | |||
"middel": "Hagen Hbf" | |||
}, | |||
"stationType": "KNOOPPUNT_SNELTREIN_STATION", | |||
"land": "D", | |||
"UICCode": "8008073", | |||
"lat": 51.362747, | |||
"lng": 7.460249, | |||
"radius": 1, | |||
"naderenRadius": 1, | |||
"EVACode": "8000142" | |||
}, { | |||
"sporen": [], | |||
"synoniemen": [], | |||
"heeftFaciliteiten": true, | |||
"heeftVertrektijden": true, | |||
"heeftReisassistentie": false, | |||
"code": "WUPPV", | |||
"namen": { | |||
"lang": "Wuppertal-Vohwinkel", | |||
"kort": "Wupp-Vohw", | |||
"middel": "Wupp-Vohwinkel" | |||
}, | |||
"stationType": "STOPTREIN_STATION", | |||
"land": "D", | |||
"UICCode": "8008082", | |||
"lat": 51.23351, | |||
"lng": 7.07237, | |||
"radius": 1, | |||
"naderenRadius": 1, | |||
"EVACode": "8006718" | |||
}, { | |||
"sporen": [], | |||
"synoniemen": [], | |||
"heeftFaciliteiten": true, | |||
"heeftVertrektijden": true, | |||
"heeftReisassistentie": false, | |||
"code": "EENP", | |||
"namen": { | |||
"lang": "Ennepetal", | |||
"kort": "Ennepetal", | |||
"middel": "Ennepetal" | |||
}, | |||
"stationType": "STOPTREIN_STATION", | |||
"land": "D", | |||
"UICCode": "8008134", | |||
"lat": 51.304892, | |||
"lng": 7.343285, | |||
"radius": 1, | |||
"naderenRadius": 1, | |||
"EVACode": "8001795" | |||
}, { | |||
"sporen": [], | |||
"synoniemen": [], | |||
"heeftFaciliteiten": true, | |||
"heeftVertrektijden": true, | |||
"heeftReisassistentie": false, | |||
"code": "KSWE", | |||
"namen": { | |||
"lang": "Schwelm", | |||
"kort": "Schwelm", | |||
"middel": "Schwelm" | |||
}, | |||
"stationType": "STOPTREIN_STATION", | |||
"land": "D", | |||
"UICCode": "8008136", | |||
"lat": 51.290526, | |||
"lng": 7.289681, | |||
"radius": 1, | |||
"naderenRadius": 1, | |||
"EVACode": "8000033" | |||
}], | |||
"meta": {} | |||
} |
@ -0,0 +1,30 @@ | |||
#!/usr/bin/env python3 | |||
#title :8-5.py | |||
#description :Opdracht 8.5 - Dict & functions | |||
#author :Marcel Haazen | |||
#email :marcel@haazen.xyz | |||
#date :04-11-2019 - 10:10 | |||
#version :0.1 | |||
#usage :python3 8-5.py | |||
#notes : | |||
#python_version :3.7.3 | |||
#============================================================================== | |||
def namen(): | |||
namen = {} | |||
while True: | |||
naam = str(input("Volgende naam: ")) | |||
if naam == "": | |||
for name in namen.keys(): | |||
if namen[name] == 1: | |||
print("Er is", namen[name], "student met de naam", name) | |||
else: | |||
print("Er zijn", namen[name], "studenten met de naam", name) | |||
break | |||
else: | |||
if naam in namen.keys(): | |||
namen[naam] = namen[naam]+1 | |||
else: | |||
namen[naam] = 1 | |||
namen() |
@ -0,0 +1,17 @@ | |||
#!/usr/bin/env python3 | |||
#title :9-1.py | |||
#description :Opdracht 9.1 - Sets | |||
#author :Marcel Haazen | |||
#email :marcel@haazen.xyz | |||
#date :04-11-2019 - 11:36 | |||
#version :0.1 | |||
#usage :python3 9-1.py | |||
#notes : | |||
#python_version :3.7.3 | |||
#============================================================================== | |||
bruin = {"Boxtel", "Best", "Beukelaan", "Eindhoven", "Helmond 't Hout", "Helmond", "Helmond Brouwhuis", "Deurne"} | |||
groen = {"Boxtel", "Best", "Beukelaan", "Eindhoven", "Geldrop", "Heeze", "Weert"} | |||
print(bruin.intersection(groen)) | |||
print(bruin.difference(groen)) | |||
print(bruin.union(groen)) |
@ -0,0 +1,34 @@ | |||
#!/usr/bin/env python3 | |||
#title :9-2.py | |||
#description :Opdracht 9.2 - Random | |||
#author :Marcel Haazen | |||
#email :marcel@haazen.xyz | |||
#date :04-11-2019 - 11:40 | |||
#version :0.1 | |||
#usage :python3 9-2.py | |||
#notes : | |||
#python_version :3.7.3 | |||
#============================================================================== | |||
import random | |||
def randomNum(): | |||
return 9 # Fair random number chosen by rolling a D20, Totally random everytime as you never know if its the same | |||
def monopolyworp(): | |||
throws = 0 | |||
while True: | |||
throw1 = random.randrange(1,7) | |||
throw2 = random.randrange(1,7) | |||
if throw1 == throw2: | |||
throws += 1 | |||
if throws == 3: | |||
print(throw1,"+",throw2,"= (Direct to jail)") | |||
break | |||
else: | |||
print(throw1,"+", throw2, "=", throw2+throw1,"(Double)") | |||
continue | |||
else: | |||
print(throw1,"+",throw2,"=", throw2+throw1) | |||
break | |||
monopolyworp() |