Initial commit

This commit is contained in:
2019-03-23 17:45:05 +08:00
commit 8ff3d31f27
3 changed files with 66 additions and 0 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

57
Problem 4.16/main.py Normal file
View File

@ -0,0 +1,57 @@
#!/usr/bin/python
import threading
import sys
average_result = None
minimum_result = None
maximum_result = None
def calculate_average(numbers: list):
global average_result
average_result = sum(numbers) / len(numbers)
def calculate_minimum(numbers: list):
global minimum_result
minimum_result = min(numbers)
def calculate_maximum(numbers: list):
global maximum_result
maximum_result = max(numbers)
def main() -> int:
if len(sys.argv) == 1:
print('Error: One or many integer arguments are necessary.')
return 1
# Converting digit strings into integers
numbers = None
try:
numbers = [int(digit) for digit in sys.argv[1:]]
except:
print('Error: Every argument must be an integer.')
return 1
# Creating threads
average_thread = threading.Thread(target=calculate_average, args=(numbers,))
minimum_thread = threading.Thread(target=calculate_minimum, args=(numbers,))
maximum_thread = threading.Thread(target=calculate_maximum, args=(numbers,))
# Starting the threads
average_thread.start()
minimum_thread.start()
maximum_thread.start()
# Waiting for the threads
average_thread.join()
minimum_thread.join()
maximum_thread.join()
# Printing the results
global average_result, minimum_result, maximum_result
print('The average value is %d' % average_result)
print('The minimum value is %d' % minimum_result)
print('The maximum value is %d' % maximum_result)
return 0
if __name__ == '__main__':
exit(main())

9
README.md Normal file
View File

@ -0,0 +1,9 @@
The 4th assignment of Operating System
===
The program of `Problem 4.16` is in the directory `Problem 4.16`.
---
The program of `Problem 4.16` requires Python 3.5.2 or newer version to execute.
To execute the program, please move to the directory and type `python main.py <arguments>` or `python3 main.py <arguments>` in your command line interface.