-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
59 lines (53 loc) · 2.73 KB
/
Copy pathclient.py
File metadata and controls
59 lines (53 loc) · 2.73 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
from functions import *
CLIENT_SOCKET = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if __name__ == "__main__":
try:
while True:
flag = test_connection(CLIENT_SOCKET, "client")
# user chooses operation
operation = int(input_validation("Choose operation: (1) MULTIPLY, (2) AVERAGE, (3) SUBTRACT or (0) EXIT to exit: ", int, min_val=0, max_val=4))
if operation == 0:
break
# if the user chooses subtraction then they should enter from 2 to 20 integers
if operation == 2:
N_integers = int(input_validation("Enter the number of inetegers (from 2 to 20): ", int, min_val=2, max_val=20))
# else the user should choose from 2 to 10 integers
else:
N_integers = int(input_validation("Enter the number of inetegers (from 2 to 10): ", int, min_val=2, max_val=10))
set0 = []
set1 = []
# input
for i in range(N_integers):
# if MULTIPLY then input > -5 and input < 5 => 1 byte signed integer
if operation == 1:
set0.append(int(input_validation(f"Enter integer: ", int, min_val=0, max_val=60000)))
continue
# if AVERAGE then input > 0 and input < 200 => 1 byte unsigned integer
elif operation == 2:
set0.append(int(input_validation(f"Enter integer: ", int, min_val=0, max_val=200)))
continue
# if SUBTRACT then input > 0 and input < 60000 => 4 byte signed integer
else:
set0.append(int(input_validation(f"Enter integer for the 1st set: ", int, min_val=0, max_val=60000)))
set1.append(int(input_validation(f"Enter integer for the 2nd set: ", int, min_val=0, max_val=60000)))
if len(set0) != len(set1):
print("The sets should have the same length !")
break
continue
if operation == 1:
sending_data(CLIENT_SOCKET, "1", set0, [])
break
elif operation == 2:
sending_data(CLIENT_SOCKET, "2", set0, [])
break
# if the sets are not empty and have the same size then this will send the sets
elif operation == 3 and (len(set0) == len(set1)) and (len(set0) != 0):
sending_data(CLIENT_SOCKET, "3", set0, set1)
break
else:
print("Unknown Error..")
break
except KeyboardInterrupt:
print("Exiting...")
finally:
CLIENT_SOCKET.close()