Looking for reliable answers? Westonci.ca is the ultimate Q&A platform where experts share their knowledge on various topics. Get detailed and accurate answers to your questions from a dedicated community of experts on our Q&A platform. Discover in-depth answers to your questions from a wide network of professionals on our user-friendly Q&A platform.
Sagot :
Answer (python):
mixednumbers = [49.5, -2, -54.5, -87.6, 17.3, 92, -1.4, 47.7, -27.4, -31.8]
numbers = []
def absolute(num):
num = abs(num)
return num
mappednumbers = map(absolute, mixednumbers)
for i in mappednumbers:
numbers.append(i)
print(numbers)
Explanation (in line numbers):
1 provides the numbers that we will work with in an array called mixednumbers
2 creates an empty array called numbers where we will store the result
4-6 create a function that will take a number, get the absolute value of it, then return it
8 is where we use our function and mixednumbers to create a map named mappednumbers (it contains the numbers in absolute value)
10-11 take each item in the map and append it to our numbers array (printing the map directly will give us a memory address)
12 prints the numbers array, giving us our solution
Output:
[49.5, 2, 54.5, 87.6, 17.3, 92, 1.4, 47.7, 27.4, 31.8]
Thanks for using our platform. We're always here to provide accurate and up-to-date answers to all your queries. Thank you for your visit. We're committed to providing you with the best information available. Return anytime for more. Find reliable answers at Westonci.ca. Visit us again for the latest updates and expert advice.