MyProjects / Oefeningen / sums.py
sums.py
Raw
from datetime import date
import pandas as pd
import random
import os.path


info = {}

df = pd.DataFrame()

def set_key(dictionary, key, value):
    if key not in dictionary:
        dictionary[key] = value
    elif type(dictionary[key]) == list:
        dictionary[key].append(value)
    else:
        dictionary[key] = [dictionary[key], value]

count = 0
maxcount = 101
print("kies een  oefen afstand, b.v: 20 of 100 of er tussen in:")
kiesrange = int(input())
print("uitleg: je ziet dadelijk drie cijfers, bv [17, 11, 13]")
print("wat je dan doet is, je pakt het hoogste cijfer eruit (17) en de laagste (11)")
print("en nu vergelijk je de afstand tussen de 17 en 13 en 11 en 13")
print("afstand tussen 17 en 13 = 4 & 11 en 13 = 2.")
print("dus de juiste antwoord is 17.")

correct = 0
wrong = 0
while True:
    count += 1
    # print("vraag", count, "van de", maxcount -1)
    if count == maxcount:
        set_key(info, "datum", date.today())
        set_key(info, "goed", str(correct))
        set_key(info, "fout", str(wrong))
        info = pd.DataFrame.from_dict(info, orient='index').transpose()
        df = pd.concat([df, info])
        if not os.path.isfile('sums-log.csv'):
            df.to_csv('sums-log.csv', index=False)
        else:
            df.to_csv('sums-log.csv', mode='a', header=None, index=False)
        print("Goed bezig geweest! :)")
        break


    def mean3(a, b, c):
        if a <= b <= c or c <= b <= a:
            return b
        elif b <= a <= c or c <= a <= b:
            return a
        else:
            return c


    A = random.randrange(1, kiesrange)
    B = random.randrange(1, kiesrange)
    C = random.randrange(1, kiesrange)

    test5 = mean3(A, B, C)

    lst = [A, B, C]
    # sorted_lst = sorted(lst)
    #  val1 = sorted_lst[1] - sorted_lst[0]
    #  val2 = sorted_lst[2] - sorted_lst[1]
    #  newlist = [val1, val2]

    #  print(lst)

    #  myinput = int(input())
    print("vraag", count, "van de", maxcount - 1)
    print("Goed:", correct, "fout:", wrong)
    print(lst)

    test = abs(max(lst) - test5)
    test2 = abs(min(lst) - test5)

    newlist = [test, test2]

    givenanswer = int(input("Number:"))

    highest = max(newlist)
    if givenanswer == max(lst) and test == highest:
        correct += 1
        print("Correct!")
    elif givenanswer == min(lst) and test2 == highest:
        correct += 1
        print("Correct!")
    else:
        wrong += 1
        print("fout!", "\n" "hoogste:", max(lst), "-", test5, "=", max(lst) - test5, "\nlaagste:", test5, "-",
              min(lst), "=", test5 - min(lst))