Виктория обнови решението на 03.11.2022 16:49 (преди над 2 години)
+# 1
+from ast import Str
+
+my_list = []
+
+my_list.append(4)
+my_list.append(4)
+my_list.append(3)
+my_list.append(3)
+my_list.append(5)
+my_list.append(5)
+my_list.append(5)
+my_list.append(-1)
+my_list.append(5)
+my_list.append(5)
+my_list.append(5)
+my_list.append(6)
+my_list.append(6)
+my_list.append(6)
+
+my_list.append(0)
+
+my_list.append(7)
+my_list.append(9)
+my_list.append(9)
+my_list.append(9)
+my_list.append(8)
+my_list.append(4)
+my_list.append(4)
+my_list.append(6)
+my_list.append(6)
+my_list.append(6)
+my_list.append(-1)
+my_list.append(6)
+my_list.append(6)
+
+def nums_to_text(nums):
+ my_word = str()
+ size = len(my_list)
+ index = 0
+ while size != 0:
+ if my_list[index] == -1:
+ size-=1
+ index+=1
+ elif my_list[index] == 0:
+ my_word += ' '
+ size-=1
+ index+=1
+ elif size>= 3 and my_list[index] == 2 and my_list[index + 1] == 2 and my_list[index + 2] == 2:
+ my_word += 'C'
+ size -=3
+ index+=3
+ elif size>= 2 and my_list[index] == 2 and my_list[index + 1] == 2:
+ my_word += 'B'
+ size -=2
+ index+=2
+ elif size>= 1 and my_list[index] == 2:
+ my_word += 'A'
+ size -=1
+ index+=1
+ elif size>= 3 and my_list[index] == 3 and my_list[index + 1] == 3 and my_list[index + 2] == 3:
+ my_word += 'F'
+ size -=3
+ index+=3
+ elif size>= 2 and my_list[index] == 3 and my_list[index + 1] == 3:
+ my_word += 'E'
+ size -=2
+ index+=2
+ elif size>= 1 and my_list[index] == 3:
+ my_word += 'D'
+ size -=1
+ index+=1
+ elif size>= 3 and my_list[index] == 4 and my_list[index + 1] == 4 and my_list[index + 2] == 4:
+ my_word += 'I'
+ size -=3
+ index+=3
+ elif size>= 2 and my_list[index] == 4 and my_list[index + 1] == 4:
+ my_word += 'H'
+ size -=2
+ index+=2
+ elif size>= 1 and my_list[index] == 4:
+ my_word += 'G'
+ size -=1
+ index+=1
+ elif size>= 3 and my_list[index] == 5 and my_list[index + 1] == 5 and my_list[index + 2] == 5:
+ my_word += 'L'
+ size -=3
+ index+=3
+ elif size>= 2 and my_list[index] == 5 and my_list[index + 1] == 5:
+ my_word += 'K'
+ size -=2
+ index+=2
+ elif size>= 1 and my_list[index] == 5:
+ my_word += 'J'
+ size -=1
+ index+=1
+ elif size>= 3 and my_list[index] == 6 and my_list[index + 1] == 6 and my_list[index + 2] == 6:
+ my_word += 'O'
+ size -=3
+ index+=3
+ elif size>= 2 and my_list[index] == 6 and my_list[index + 1] == 6:
+ my_word += 'N'
+ size -=2
+ index+=2
+ elif size>= 1 and my_list[index] == 6:
+ my_word += 'M'
+ size -=1
+ index+=1
+ elif size>= 4 and my_list[index] == 7 and my_list[index + 1] == 7 and my_list[index + 2] == 7 and my_list[index + 3] == 7:
+ my_word += 'S'
+ size -=3
+ index+=3
+ elif size>= 3 and my_list[index] == 7 and my_list[index + 1] == 7 and my_list[index + 2] == 7:
+ my_word += 'R'
+ size -=3
+ index+=3
+ elif size>= 2 and my_list[index] == 7 and my_list[index + 1] == 7:
+ my_word += 'Q'
+ size -=2
+ index+=2
+ elif size>= 1 and my_list[index] == 7:
+ my_word += 'P'
+ size -=1
+ index+=1
+ elif size>= 3 and my_list[index] == 8 and my_list[index + 1] == 8 and my_list[index + 2] == 8:
+ my_word += 'V'
+ size -=3
+ index+=3
+ elif size>= 2 and my_list[index] == 8 and my_list[index + 1] == 8:
+ my_word += 'U'
+ size -=2
+ index+=2
+ elif size>= 1 and my_list[index] == 8:
+ my_word += 'T'
+ size -=1
+ index+=1
+ elif size>= 4 and my_list[index] == 9 and my_list[index + 1] == 9 and my_list[index + 2] == 9 and my_list[index + 3] == 9:
+ my_word += 'Z'
+ size -=4
+ index+=4
+ elif size>= 3 and my_list[index] == 9 and my_list[index + 1] == 9 and my_list[index + 2] == 9:
+ my_word += 'Y'
+ size -=3
+ index+=3
+ elif size>= 2 and my_list[index] == 9 and my_list[index + 1] == 9:
+ my_word += 'X'
+ size -=2
+ index+=2
+ elif size>= 1 and my_list[index] == 9:
+ my_word += 'W'
+ size -=1
+ index+=1
+ return my_word
+
+print(nums_to_text(my_list))
+
+
+
+# 2
+
+from asyncio.windows_events import NULL
Явно имаш проблем с редактора си. Едва ли това е import
, който умишлено си добавила.
Виж какъв е проблема, защото това ти е коствало всички точки.
+
+string = "GOD"
+
+def text_to_nums(str):
+ str = [*str]
+ size = len(str)
+ for el in range(0, len(str)):
+ str[el] = str[el].upper()
+
+ nums_names = { 'A': '2', 'B': '22', 'C': '222', 'D': '3', 'E': '33', 'F': '333',
+ 'G': '4', 'H': '44', 'I': '444', 'J': '5', 'K': '55', 'L': '555', 'M': '6',
+ 'N': '66', 'O': '666', 'P': '7', 'Q': '77', 'R': '777', 'S': '7777',
+ 'T': '8', 'U': '88', 'V': '888', 'W': '9', 'X': '99', 'Y': '999', 'Z': '9999' }
+
+ index = 0
+ list = []
+ while size != 0:
+ if str[index] in nums_names:
+ size = size - 1
+ list += nums_names[str[index]]
+ index+=1
+ else:
+ size-=1
+ index+=1
+ list += '0'
+
+ return list
+
+print(text_to_nums(string))
+
+# 3
+
+nums = []
+
+nums.append(4)
+nums.append(6)
+nums.append(6)
+nums.append(6)
+nums.append(3)
+
+def nums_to_angles(nums):
+ size = len(nums)
+ sum = 0
+ index = 0
+ nums_angles = { 1: 30, 2: 60, 3: 90, 4: 120, 5: 150,
+ 6: 180, 7: 210, 8: 240, 9: 270, 0: 300 }
+ arr = []
+ while size != 0:
+ if nums[index] in nums_angles:
+ arr.append(nums_angles[nums[index]])
+ size -= 1
+ index += 1
+ else:
+ size -= 1
+ index += 1
+
+ for ele in range(0, len(arr)):
+ sum = sum + arr[ele]
+
+ while sum > 360:
+ sum -= 360
+
+ return sum
+
+print(nums_to_angles(nums))
+
+
+# 4
+
+angles = []
+angles.append(16)
+angles.append(14)
+angles.append(90)
+angles.append(-120)
+
+llist = []
+def angles_to_nums(angles):
+ nums_angles = { 1: 30, 2: 60, 3: 90, 4: 120, 5: 150,
+ 6: 180, 7: 210, 8: 240, 9: 270, 0: 300 }
+
+ angles_nums = { 30: 1, 60: 2, 90: 3, 120: 4, 150: 5,
+ 180: 6, 210: 7, 240: 8, 270: 9, 300: 0 }
+ arr = []
+ index = 0
+ size = len(angles)
+ x = 0
+ while size != 0:
+ if angles[index] < 0:
+ while angles[index] < 0:
+ angles[index] = 360 + angles[index]
+
+ if angles[index] >= 0 and angles[index] <= 30:
+ x = 30 - angles[index]
+ if x < angles[index]:
+ llist.append(angles_nums[30])
+ index+=1
+ size -=1
+ elif angles[index] >= 30 and angles[index] <= 60:
+ x = 60 - angles[index]
+ if x < angles[index]:
+ llist.append(angles_nums[60])
+ else:
+ llist.append(angles_nums[30])
+ index+=1
+ size -=1
+ elif angles[index] >= 60 and angles[index] <= 90:
+ x = 90 - angles[index]
+ if x < angles[index]:
+ llist.append(angles_nums[90])
+ else:
+ llist.append(angles_nums[60])
+ index+=1
+ size -=1
+ elif angles[index] >= 90 and angles[index] <= 120:
+ x = 120 - angles[index]
+ if x < angles[index]:
+ llist.append(angles_nums[120])
+ else:
+ llist.append(angles_nums[90])
+ index+=1
+ size -=1
+ elif angles[index] >= 120 and angles[index] <= 150:
+ x = 150 - angles[index]
+ if x < angles[index]:
+ llist.append(angles_nums[150])
+ else:
+ llist.append(angles_nums[120])
+ index+=1
+ size -=1
+ elif angles[index] >= 160 and angles[index] <= 180:
+ x = 180 - angles[index]
+ if x < angles[index]:
+ llist.append(angles_nums[180])
+ else:
+ llist.append(angles_nums[120])
+ index+=1
+ size -=1
+ elif angles[index] >= 180 and angles[index] <= 210:
+ x = 210 - angles[index]
+ if x < angles[index]:
+ llist.append(angles_nums[210])
+ else:
+ llist.append(angles_nums[180])
+ index+=1
+ size -=1
+ elif angles[index] >= 210 and angles[index] <= 240:
+ x = 240 - angles[index]
+ if x < angles[index]:
+ llist.append(angles_nums[240])
+ else:
+ llist.append(angles_nums[210])
+ index+=1
+ size -=1
+ elif angles[index] >= 240 and angles[index] <= 270:
+ x = 270 - angles[index]
+ if x < angles[index]:
+ llist.append(angles_nums[270])
+ else:
+ llist.append(angles_nums[240])
+ index+=1
+ size -=1
+ elif angles[index] >= 270 and angles[index] <= 300:
+ x = 300 - angles[index]
+ if x < angles[index]:
+ llist.append(angles_nums[300])
+ else:
+ llist.append(angles_nums[270])
+ index+=1
+ size -=1
+ elif angles[index] >= 300 and angles[index] <= 360:
+ index += 1
+ size -= 1
+
+ return llist
+
+print(angles_to_nums(angles))
+
+
+# 5
+
+from xml.etree.ElementInclude import include
+
+def text_to_nums(str):
+ str = [*str]
+ size = len(str)
+ for el in range(0, len(str)):
+ str[el] = str[el].upper()
+
+ nums_names = { 'A': '2', 'B': '22', 'C': '222', 'D': '3', 'E': '33', 'F': '333',
+ 'G': '4', 'H': '44', 'I': '444', 'J': '5', 'K': '55', 'L': '555', 'M': '6',
+ 'N': '66', 'O': '666', 'P': '7', 'Q': '77', 'R': '777', 'S': '7777',
+ 'T': '8', 'U': '88', 'V': '888', 'W': '9', 'X': '99', 'Y': '999', 'Z': '9999'}
+
+ index = 0
+ list=[]
+ while size != 0:
+ if str[index] in nums_names:
+ size=size - 1
+ list += nums_names[str[index]]
+ index+=1
+ else:
+ size -= 1
+ index += 1
+ list += '0'
+
+ return list
+
+
+def nums_to_angles(num):
+ size = len(num)
+ sum = 0
+ index = 0
+ nums_angles = { 1: 30, 2: 60, 3: 90, 4: 120, 5: 150,
+ 6: 180, 7: 210, 8: 240, 9: 270, 0: 300 }
+ arr = []
+ while size != 0:
+ if num[index] in nums_angles:
+ arr.append(nums_angles[num[index]])
+ size -= 1
+ index += 1
+ else:
+ size -= 1
+ index += 1
+
+ for ele in range(0, len(arr)):
+ sum = sum + arr[ele]
+
+ while sum > 360:
+ sum -= 360
+
+ return sum
+
+
+string = "GOD"
+
+def is_phone_tastic(string):
+ listt = []
+ listt = text_to_nums(string)
+
+ angle = 0
+ x = angle + nums_to_angles(listt)
+
+ size = len(string)
+
+ if angle % size == 0:
+ return True
+ else:
+ return False
+
+print(is_phone_tastic(string))
+
Очевидно имаш проблем с тестовете, защото кодът ти импортира разни неща. Инак, кодът ти е доста усложнен и те съветвам да погледнеш вече публичните решения на колегите, за да събереш малко идеи. Тъй като си написала доста код, опитах да го изчистя от проблемните импорти и да пусна тестовете ръчно, но пак нямаш минаващ тест :( Логиката изглежда адекватна, но имаш пропуски, поради които резултатите са ти грешни. Опитай да тестваш по-усърдно следващия път.
Явно имаш проблем с редактора си. Едва ли това е
import
, който умишлено си добавила. Виж какъв е проблема, защото това ти е коствало всички точки.