|
@ -0,0 +1,86 @@ |
|
|
|
|
|
#!/usr/bin/env python3 |
|
|
|
|
|
#title :FA-2.py |
|
|
|
|
|
#description :Final Assignment: Bagagekluizen |
|
|
|
|
|
#author :Marcel Haazen |
|
|
|
|
|
#email :marcel@haazen.xyz |
|
|
|
|
|
#date :04-10-2019 - 21:25 |
|
|
|
|
|
#version :0.1 |
|
|
|
|
|
#usage :python3 FA-2.py |
|
|
|
|
|
#notes : |
|
|
|
|
|
#python_version :3.7.4 |
|
|
|
|
|
#============================================================================== |
|
|
|
|
|
exit = False |
|
|
|
|
|
|
|
|
|
|
|
def find_missing(lst): |
|
|
|
|
|
return [x for x in range(lst[0], lst[-1]+1) |
|
|
|
|
|
if x not in lst] |
|
|
|
|
|
|
|
|
|
|
|
def toon_aantal_kluizen_vrij(): |
|
|
|
|
|
num_lines = sum(1 for line in open("kluizen.txt")) |
|
|
|
|
|
free = 12 - num_lines |
|
|
|
|
|
return free |
|
|
|
|
|
|
|
|
|
|
|
def nieuwe_kluis(): |
|
|
|
|
|
file = open("kluizen.txt", "r+") |
|
|
|
|
|
gebruikt = [] |
|
|
|
|
|
rules = file.readlines() |
|
|
|
|
|
for x in rules: |
|
|
|
|
|
y = x.split(";") |
|
|
|
|
|
gebruikt.append(int(y[0])) |
|
|
|
|
|
gebruikt.sort() |
|
|
|
|
|
kluisnummers = find_missing(gebruikt) |
|
|
|
|
|
for rule in rules: |
|
|
|
|
|
y = rule.split(";") |
|
|
|
|
|
if (len(kluisnummers)) > 0: |
|
|
|
|
|
kluis_code = str(input("Geef een code op voor uw kluis (minimaal 4 karakters):")) |
|
|
|
|
|
if len(kluis_code) >= 4: |
|
|
|
|
|
toegewezen_kluisnummer = str(kluisnummers[0]) |
|
|
|
|
|
file.write(toegewezen_kluisnummer + ";" + kluis_code + "\n") |
|
|
|
|
|
return "\nJe nieuwe kluisnummer is: " + str(toegewezen_kluisnummer) + "\n" |
|
|
|
|
|
else: |
|
|
|
|
|
print("De opgegeven code is te kort (minimaal 4 karakters)") |
|
|
|
|
|
else: |
|
|
|
|
|
return "\ner is niks meer vrij\n" |
|
|
|
|
|
file.close() |
|
|
|
|
|
|
|
|
|
|
|
def kluis_openen(kluisnummer,code): |
|
|
|
|
|
file = open("kluizen.txt", "r+") |
|
|
|
|
|
rules = file.readlines() |
|
|
|
|
|
for rule in rules: |
|
|
|
|
|
if str(kluisnummer) + ";" + code + "\n" == rule: |
|
|
|
|
|
return "\nDe kluis is geopend\n" |
|
|
|
|
|
else: |
|
|
|
|
|
return "\nDe ingevoerde gegevens zijn niet correct\n" |
|
|
|
|
|
file.close() |
|
|
|
|
|
|
|
|
|
|
|
def kluis_teruggeven(kluisnummer,code): |
|
|
|
|
|
file = open("kluizen.txt", "r+") |
|
|
|
|
|
rules = file.readlines() |
|
|
|
|
|
file.close() |
|
|
|
|
|
for rule in rules: |
|
|
|
|
|
if str(kluisnummer) + ";" + code + "\n" == rule: |
|
|
|
|
|
rules.remove(str(kluisnummer) + ";" + code + "\n") |
|
|
|
|
|
file = open("kluizen.txt", "w") |
|
|
|
|
|
file.writelines(rules) |
|
|
|
|
|
file.close() |
|
|
|
|
|
return "\nDe kluis is vrijgegeven\n" |
|
|
|
|
|
return "\nDe ingevoerde gegevens zijn niet correct\n" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while exit != True: |
|
|
|
|
|
print("1: Ik wil weten hoeveel kluizen nog vrij zijn \n2: Ik wil een nieuwe kluis \n3: Ik wil even iets uit mijn kluis halen \n4: Ik geef mijn kluis terug\n5: ik wil stoppen") |
|
|
|
|
|
num = int(input("Kies wat je wilt doen: ")) |
|
|
|
|
|
if num == 5: |
|
|
|
|
|
exit = True |
|
|
|
|
|
elif num == 1: |
|
|
|
|
|
print("\nEr zijn",toon_aantal_kluizen_vrij(),"kluizen vrij \n") |
|
|
|
|
|
elif num == 2: |
|
|
|
|
|
print(nieuwe_kluis()) |
|
|
|
|
|
elif num == 3: |
|
|
|
|
|
kn = input("wat is je kluisnummer? ") |
|
|
|
|
|
kc = input("wat is je code? ") |
|
|
|
|
|
print(kluis_openen(kn,kc)) |
|
|
|
|
|
elif num == 4: |
|
|
|
|
|
kn = input("wat is je kluisnummer? ") |
|
|
|
|
|
kc = input("wat is je code? ") |
|
|
|
|
|
print(kluis_teruggeven(kn,kc)) |