Дейвид обнови решението на 19.10.2022 14:50 (преди около 2 години)
+# Homework1 Introduction to Python
+# Created by Deivid Kamenov 62585
+
+# Task Description:
+# hue and saturation give information about the certain direction we're moving to
+
+# colours -> directions
+# green -> right x COORDINATE
+# red -> left X COORDINATE
+# yellow -> up Y COORDINATE
+# blue -> down Y COORDINATE
+
+# saturation -> back or forth the direction
+# light -> -1 to the direction
+# dark -> +1 to the direction
+#
+
+# Special colours
+# Black - 000000 END
+# White - FFFFFF - nothing happens
+
+# Solution function; Solution 1
+def calculate_final_vector(vector, codes):
+ # print(vector)
+ for code in codes:
+ if code == 'C0FFC0' or code == 'c0ffc0':
+ vector[0] -= 1
+ # print(f'light green {vector}')
+
+ elif code == '00C000' or code == '00c000':
+ vector[0] += 1
+ # print(f'dark green {vector}')
+
+ elif code == 'FFFFC0' or code == 'ffffc0':
+ vector[1] -= 1
+ # print(f'light yellow {vector}')
+
+ elif code == 'C0C000' or code == 'c0c000':
+ vector[1] += 1
+ # print(f'dark yellow {vector}')
+
+ elif code == 'FFC0C0' or code == 'ffc0c0':
+ vector[0] += 1
+ # print(f'light red {vector}')
+
+ elif code == 'C00000' or code == 'c00000':
+ vector[0] -= 1
+ # print(f'dark red {vector}')
+
+ elif code == 'C0C0FF' or code == 'c0c0ff':
+ vector[1] += 1
+ # print(f'light blue {vector}')
+
+ elif code == '0000C0' or code == '0000c0':
+ vector[1] -= 1
+ # print(f'dark blue {vector}')
+
+ elif code == 'FFFFFF' or code == 'ffffff':
+ # print(f'white {vector}')
+ continue
+
+ elif code == '000000' or code == '000000':
+ # print(f'black {vector}')
+ break
+
+ # default
+ else:
+ print(f'Error, unknown color has been inputted! {vector}')
+ return None
+
+ return vector
Version 2 using match/case
This version of the code will only work on Python 3.10 or later
def calculate_final_vector_v2(vector, codes): # print(vector) for code in codes: match code: case 'C0FFC0' | 'c0ffc0': vector[0] -= 1 # print(f'light green {vector}')
case '00C000' | '00c000':
vector[0] += 1
# print(f'dark green {vector}')
case 'FFFFC0' | 'ffffc0':
vector[1] -= 1
# print(f'light yellow {vector}')
case 'C0C000' | 'c0c000':
vector[1] += 1
# print(f'dark yellow {vector}')
case 'FFC0C0' | 'ffc0c0':
vector[0] += 1
# print(f'light red {vector}')
case 'C00000' | 'c00000':
vector[0] -= 1
# print(f'dark red {vector}')
case 'C0C0FF' | 'c0c0ff':
vector[1] += 1
# print(f'light blue {vector}')
case '0000C0' | '0000c0':
vector[1] -= 1
# print(f'dark blue {vector}')
case 'FFFFFF' | 'ffffff':
# print(f'white {vector}')
continue
case '000000' | '000000':
# print(f'black {vector}')
break
# default
case _:
print(f'Error, unknown color has been inputted! {vector}')
continue
return vector