From 1042a5d8eac38e9fa7f65ccb2792cf246c6d5093 Mon Sep 17 00:00:00 2001 From: Marcel Haazen Date: Tue, 29 Oct 2019 10:24:34 +0100 Subject: [PATCH] Final assignmetn 8 almost done --- les 8/8-1.py | 19 +++++++++++++++++++ les 8/8-4.py | 30 ++++++++++++++++++++++++++++++ les 8/tickers.txt | 6 ++++++ 3 files changed, 55 insertions(+) create mode 100644 les 8/8-1.py create mode 100644 les 8/8-4.py create mode 100644 les 8/tickers.txt diff --git a/les 8/8-1.py b/les 8/8-1.py new file mode 100644 index 0000000..0b89473 --- /dev/null +++ b/les 8/8-1.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 +#title :8-1.py +#description :Opdracht 8.1 - While-loop & numbers +#author :Marcel Haazen +#email :marcel@haazen.xyz +#date :28-10-2019 - 13:10 +#version :0.1 +#usage :python3 8-1.py +#notes : +#python_version :3.7.3 +#============================================================================== +nl = [] +n = None +i = 0 +while n != 0: + n = int(input("Voer een nummer in: ")) + nl.append(n) + i += 1 +print("er zijn", i-1 ,"getallen ingevoerd, de som is:", sum(nl)) diff --git a/les 8/8-4.py b/les 8/8-4.py new file mode 100644 index 0000000..cae442e --- /dev/null +++ b/les 8/8-4.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +#title :8-4.py +#description :Opdracht 8.4 - File & dict +#author :Marcel Haazen +#email :marcel@haazen.xyz +#date :28-10-2019 - 13:20 +#version :0.1 +#usage :python3 8-4.py +#notes : +#python_version :3.7.3 +#============================================================================== +def ticker(): + filename = 'tickers.txt' + tickers = {} + with open(filename) as fh: + for line in fh: + company, ticker = line.strip().split(':', 1) + tickers[company] = ticker.strip() + return tickers +try: + comp = str(input("Enter Company name: ")).upper() + print((ticker())[comp]) +except KeyError as identifier: + print("Dit bedrijf in onbekend.") + +try: + tick = comp = str(input("Enter Ticker symbol: ")).upper() + print([key for key in ticker().items() if key[1] == tick][0][0]) +except StopIteration as identifier: + print("Dit bedrijf in onbekend.") \ No newline at end of file diff --git a/les 8/tickers.txt b/les 8/tickers.txt new file mode 100644 index 0000000..00aa6a8 --- /dev/null +++ b/les 8/tickers.txt @@ -0,0 +1,6 @@ +YAHOO:YHOO +GOOGLE INC:GOOG +Harley-Davidson:HOG +Yamana Gold:AUY +Sotheby's:BID +inBev:BUD \ No newline at end of file