Python code Python code..PLEASE follow exactly the instructions bellow...Don\'t
ID: 3757985 • Letter: P
Question
Python code
Python code..PLEASE follow exactly the instructions bellow...Don't use split/stride methods..Don't request to rewrite this question because you don't know how to answer this question or you don't have the software because you even know python or you don't know how to answer.....This is the third time I post this question
.Use "np.sort " and the negative sign is for descending form....Don't answer if it is not something you will know how to answer..".use a loop" for placing each array that is now sorted in the appropriate array.
Python code..Can someone help to write this code:
Step1.Write a python program that creates an array that contains 38 numbers .
14,175, 15,055, 16,616, 17,495, 18,072, 19,390, 19,731, 22,161, 23,320,
23,717, 26,343, 28,725, 29,127, 32,257, 40,020, 41,867, 43,155, 46,298,
56,734, 57,176, 58,306, 61,848, 65,825, 66,042, 68,634, 69,189, 72,936,
74,287, 74,537, 81,942, 82,027, 82,623, 82,802, 82,988, 90,467, 97,042,
97,507, 99,564
Step2. Sort the array into another array in a descending way
Try to exactly as this code:
a = -np.sort(-b)
a is one array that is sorted in descending order
b is another array that has the 38 numbers
Step3. Create sum1 AND sum2 in which sum1 and sum2 split arrays (38 number) each containing 19 numbers:
use a for loop and if (sum(sum1) <= sum(sum2)
put sum1 = np.append (sum1,s[i])
else sum2 = np.append(sum2, s[i])
print sum1 and sum2 and then print sum(sum1) and sum(sum2)
Explanation / Answer
Def Array
list = ["14" "175" "15" "055" "16" "616" "17" "495" "18" "072" "19" "390" "19" "731" "22" "161" "23" "320" "23" "717"
"26" "343" "28" "725" 29" "127" "32" "257" "40" "020" "41" "867" "43" "155" "46" "298" "56" "734" "57" "176" "58" "306" "61" "848"
"65" "825" "66" "042" "68" "634" "69" "189" "72" "936" "74" "287" "74" "537" "81" "942" "82" "027" "82" "623" "82" "802" "82" "988"
"90" "467" "97" "042" "97" "507" "99" "564"]
# Insert at index .
list.insert(1, "14")
list.insert(2, "343")
list.insert(3, "28")
list.insert(4, "725")
list.insert(5, "29")
list.insert(6, "127")
list.insert(7, "32")
list.insert(8, "257")
list.insert(9, "40")
list.insert(10, "020")
list.insert(11, "41")
list.insert(12, "867")
list.insert(13, "43")
list.insert(14, "155")
list.insert(15, "46")
list.insert(16, "298")
list.insert(17, "56")
list.insert(18, "734")
list.insert(19, "57")
list.insert(20, "176")
list.insert(21, "58")
list.insert(22, "306")
list.insert(23, "61")
list.insert(24, "848")
list.insert(25, "65")
list.insert(26, "825")
list.insert(27, "66")
list.insert(28, "042")
list.insert(29, "68")
list.insert(30, "634")
list.insert(31, "69")
list.insert(32, "189")
list.insert(33, "72")
list.insert(34, "936")
list.insert(36, "74")
list.insert(37, "287")
list.insert(38, "74")
list.insert(39, "537")
list.insert(40, "81")
list.insert(41, "942")
list.insert(42, "82")
list.insert(43, "027")
list.insert(44, "82")
list.insert(45, "623")
list.insert(46, "82")
list.insert(47, "802")
list.insert(48, "82")
list.insert(49, "988")
list.insert(50, "90")
list.insert(51, "467")
list.insert(52, "97")
list.insert(53, "042")
list.insert(54, "97")
list.insert(55, "507")
list.insert(56, "99")
list.insert(57, "564")
print(list)
end
2)
Def Sort
# Contains unsortedintegers.
elements = [14,175, 15,055, 16,616, 17,495, 18,072, 19,390, 19,731, 22,161, 23,320,23,717, 26,343, 28,725, 29,127, 32,257, 40,020, 41,867, 43,155, 46,298,56,734, 57,176, 58,306, 61,848, 65,825, 66,042, 68,634, 69,189, 72,936,74,287, 74,537, 81,942, 82,027, 82,623, 82,802, 82,988, 90,467, 97,042,97,507, 99,564]
# Sort from hign to low
a = -np.sort(-b)
print(elements)
end
3)
def List_Split(List,*lindex):
index = list(lindex)
index.sort()
sum1 = []
sum2 = []
breakcounter = 0
itemcounter = 0
finalcounter = 0
numberofbreaks = len(index)
totalitems = len(List)
lastindexval = index[(len(index)-1)]
finalcounttrigger = (totalitems-(lastindexval+1))
for item in List:
itemcounter += 1
indexofitem = itemcounter - 1
nextbreakindex = index[breakcounter]
#Less than the last cut
if breakcounter <= numberofbreaks:
if indexofitem < nextbreakindex:
sum1.append(item)
elif breakcounter < (numberofbreaks - 1):
sum1.append(item)
sum2.append(templist1)
sum1 = []
breakcounter +=1
else:
if indexofitem <= lastindexval and indexofitem <= totalitems:
sum1.append(item)
sum2.append(templist1)
sum1 = []
returnsum2
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.