summaryrefslogtreecommitdiff
path: root/9618-42-mj-2022/Question3_J22.py
diff options
context:
space:
mode:
Diffstat (limited to '9618-42-mj-2022/Question3_J22.py')
-rw-r--r--9618-42-mj-2022/Question3_J22.py25
1 files changed, 14 insertions, 11 deletions
diff --git a/9618-42-mj-2022/Question3_J22.py b/9618-42-mj-2022/Question3_J22.py
index 764f4c0..384e9e3 100644
--- a/9618-42-mj-2022/Question3_J22.py
+++ b/9618-42-mj-2022/Question3_J22.py
@@ -13,17 +13,20 @@ class Card:
# 3 c
TEXT_FILE_NAME = "CardValues.txt"
cards = [None for i in range(30)] # type is Card, use NoneType to indicate empty
-with open(TEXT_FILE_NAME, "r") as file:
- i = 0
- j = 0
- text_lines = file.readlines()
- #print(text_lines)
- while i < 30:
- number = int(text_lines[j])
- colour = text_lines[j+1]
- cards[i] = Card(number, colour.strip())
- i += 1
- j += 2
+try:
+ with open(TEXT_FILE_NAME, "r") as file:
+ i = 0
+ j = 0
+ text_lines = file.readlines()
+ #print(text_lines)
+ while i < 30:
+ number = int(text_lines[j])
+ colour = text_lines[j+1]
+ cards[i] = Card(number, colour.strip())
+ i += 1
+ j += 2
+except IOError:
+ print("Cannot find file.")
#print(cards)
# 3 d
selected_cards = [False for i in range(30)]