-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory_game.py
More file actions
75 lines (48 loc) · 2.16 KB
/
memory_game.py
File metadata and controls
75 lines (48 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import random
import time
class MemoryGame:
def __init__(self):
self.sequence = []
self.sequence_length = 5
def play(self):
print("\n--- Memory Game ---")
print(f"Memorize the sequence of {self.sequence_length} numbers!")
time.sleep(1)
self.sequence = []
count = 0
while count < self.sequence_length:
num = random.randint(1, 20)
self.sequence.append(num)
count = count + 1 # קידום המונה
print("Sequence: ", self.sequence)
time.sleep(2)
print("\n" * 100)
print("Time's up! Recall the numbers.")
while True:
user_input = input("Enter numbers separated by space (or 'q' to quit): ")
if user_input == 'q':
print("Gave up? The sequence was:", self.sequence)
break
try:
input_list_strings = user_input.split()
user_sequence = []
i = 0
while i < len(input_list_strings):
current_string = input_list_strings[i]
number = int(current_string)
user_sequence.append(number)
i = i + 1
if user_sequence == self.sequence:
print("AMAZING! You have a perfect memory!")
break
else:
correct_count = 0
j = 0 # מונה חדש לבדיקה
# לרוץ כל עוד לא הגענו לסוף של אחת הרשימות
while j < len(self.sequence) and j < len(user_sequence):
if self.sequence[j] == user_sequence[j]:
correct_count = correct_count + 1
j = j + 1
print("Not quite. You got " + str(correct_count) + " correct numbers in place. Try again!")
except ValueError:
print("Please enter valid numbers only.")