Code to be written in Python
Will award brainliest automatically if correct!

Suppose that you have a list of numbers, and you need to normalize the list, i.e., the sum of all numbers in the list is equal to 1.

Tam came out with an implementation:

def normalize(lst):
s = sum(lst)
return list(map(lambda v: v / s, lst))


This code works correctly for normalize([1, 2, 5, 4]) but fails for normalize([1, 2, -7, 4]). What causes the second test case to fail?

Find out the error message and keep the list as it is when the error occurs by simply return the list. So without modifying the normalize function, implement this strategy in the safe_normalize function. Complete safe_normalize. You may assume that the normalize function has already been defined for you.

def safe_normalize(lst):
# handle the error
return normalize(lst)

Test Cases:

safe_normalize([1, 2, 2, 3]) [0.125, 0.25, 0.25, 0.375]
safe_normalize([1, 2, -5, 2]) [1, 2, -5, 2]

Answers

Answer 1
PYTHON

Here is an implementation of the safe_normalize function that catches the error and returns the original list if an error occurs:

def safe_normalize(lst):

try:

return normalize(lst)

except ZeroDivisionError:

return lst

This function calls the normalize function, which takes a list as input and returns a normalized list. However, if an error occurs (in this case, a ZeroDivisionError), the function will catch the error and return the original list instead.

To test the safe_normalize function, you can use the following test cases:

print(safe_normalize([1, 2, 2, 3])) # Expected output: [0.125, 0.25, 0.25, 0.375]

print(safe_normalize([1, 2, -5, 2])) # Expected output: [1, 2, -5, 2]

The first test case should return the normalized list, while the second test case should return the original list, since the normalize function would fail with a ZeroDivisionError if passed a list with a negative sum.

Hope This Helps You!


Related Questions

Which computers were the first PCs with a GUI
MS-DOS
Linux
Windows
Mac

Answers

The earliest GUI-equipped PCs were Linux and Mac-based. These are the right answers to the question that was asked.

Which PCs had a graphical user interface (GUI) first?

The first computer to employ a mouse, the desktop metaphor, and a graphical user interface (GUI), concepts Douglas Engelbart first introduced while at International, was the Xerox Alto, developed at Xerox PARC in 1973. It was the first instance of what is now known as a full-fledged personal computer.

When was the GUI added to Windows?

Windows is based on what is known as a graphical user interface (GUI), which was created by Xerox in 1975 but was never used. The "window, icon, menu, and pointing device" (WIMP) combination will make up the majority of a typical GUI.

To learn more about GUI visit:

brainly.com/question/14758410

#SPJ1

Write an expression that will cause the following code to print "greater than 20" if the value of user_age is greater than 20.

Answers

Answer:

if user_age > 20:

   print("greater than 20")

Explanation:

Meredith's repair business has two offices—one on the east side of town and one on the west side. An employee may work out of one office on one day and the other office on the next, based on the workload on a given day. For this reason, Meredith found it useful to set up a network to connect both offices. The company's important files are stored on a server so that employees can access the information they need from either location. The type of network Meredith's business is most likely using is a _____.

WAN
MAN
LAN

Answers

Answer:

MAN

Explanation:

brainliest?:(

Answer:

WAN (Wide Area Network)


3. Describe how homes and businesses use networks.

Answers

Homes and Businesses use networks because it can help you better to find customers and staff and suppliers and business partners. Homes and Businesses also use network when it comes to conferences and you can also communicate through apps using the network.
There are many ways that homes and businesses use networks. Here are a few examples:

1. Home networks: Many homes have a local area network (LAN) that connects all of the devices in the home, such as computers, printers, and smartphones. This allows people to share resources, such as files, printers, and internet access.
2. Business networks: Businesses often have a more complex network setup, with a LAN that connects all of the devices in the office, as well as a wider area network (WAN) that connects multiple offices in different locations. This allows employees to share resources and communicate with each other, no matter where they are located.
3. The Internet: Both homes and businesses use the internet to connect to the rest of the world. This allows them to access a wide range of information and services, as well as communicate with people all over the globe.
4. Cloud computing: Many businesses and even some homes are using cloud computing, which allows them to store and access data and applications over the internet, rather than on a local server or computer. This can be more convenient and cost-effective, as it reduces the need for expensive hardware and IT staff.
5. Internet of Things (IoT): Both homes and businesses are using networks to connect a variety of devices that make up the Internet of Things (IoT). This includes things like smart thermostats, security cameras, and appliances that can be controlled and monitored over the internet.

Assignment 3: Chatbot
What the code for assignment 3: chatbot Edhesive.

Answers

Coding is difficult but I don't have a chatbot

Answer:

import random

# Introduction

print("Welcome to the fashion chatbot! I'm here to help you with your fashion preferences.")

# Ask for user's first name

print("What is your first name?")

name = input()

# Ask for user's shoe preference

print("What shoes do you like?")

shoe_preference = input()

# Use if-elif-else statement to respond to user's shoe preference

if shoe_preference == "Converse":

 print("Nice, casual is always in!")

elif shoe_preference == "Boots":

 print("Cool, boots are a versatile choice.")

else:

 print("Great choice!")

# Ask for user's age

print("How old are you?")

age = input()

# Use if-elif-else statement to respond to user's age

if int(age) < 18:

 print("It's a great time to start exploring your style!")

elif int(age) < 25:

 print("You're at a fun age to experiment with your fashion choices.")

else:

 print("It's always a good time to try out new fashion styles!")

# Use a randomly generated number to randomly respond

random_number = random.randint(1, 3)

if random_number == 1:

 print("I think I might know your style.")

elif random_number == 2:

 print("You have a unique sense of style.")

else:

 print("You have great fashion taste.")

# Ask for user's favorite top

print("So, " + name + ", what is your favorite top?")

top_preference = input()

# Use if-elif-else statement to respond to user's top preference

if top_preference == "Graphic Tees":

 print("That's a good choice.")

elif top_preference == "Button-up shirts":

 print("Classy and sophisticated.")

else:

 print("Great choice!")

# Use a randomly generated number to randomly respond

random_number = random.randint(1, 3)

if random_number == 1:

 print("Ay that's lit.")

elif random_number == 2:

 print("wow, so stylish!")

else:

 print("That's in right now.")

# Ask for user's bottom preference

print("I like where this is going.")

print("What about your choice of bottom?")

bottom_preference = input()

# Use if-elif-else statement to respond to user's bottom preference

if bottom_preference == "Jeans":

 print("Jeans are a classic choice.")

elif bottom_preference == "Cargo pants":

 print("You can't go wrong with those.")

else:

 print("Great choice!")

# Ask for user's head accessory preference

print("What about your head accessory?")

head_accessory_preference = input()

# Use if-elif-else statement to respond to user's head accessory preference

if head_accessory_preference == "Beanies":

   print("Beanies are fun!")

elif head_accessory_preference == "Baseball hats":

   print("Baseball hats are a popular choice.")

else:

   print("Unique choice!")

# End conversation

print("Well, " + name + ", it was awesome getting to know your style.")

Write a Java program that have ten integral values into an array namely List. Your program
should have a menu to select/perform the following functions :-
lnsert ( ) - accept a value into the array if it's not full
Remove ( ) - remove a value from an array if it's not empty based on user selection
Search ( ) - Return the numbers of the particular search value
lncrease ( ) - lncrease the percentage of the store value based onto the input percentage
Update ( ) - Edit the existing value choose by user.

Answers

Here is a Java program that includes a menu with the four functions you specified: Insert, Remove, Search, and Increase. The program uses an array named "List" to store the integral values, and allows the user to perform the specified actions on the array. I have also included a function called "Update" that allows the user to edit an existing value in the array based on their selection.

import java.util.Scanner;

public class ArrayMenu {
static Scanner input = new Scanner(System.in);
static int[] List = new int[10];
static int size = 0;

public static void main(String[] args) {
boolean exit = false;
while (!exit) {
System.out.println("Menu:");
System.out.println("1. Insert a value");
System.out.println("2. Remove a value");
System.out.println("3. Search for a value");
System.out.println("4. Increase the value of all elements by a percentage");
System.out.println("5. Update an existing value");
System.out.println("6. Exit");
System.out.print("Enter your choice: ");
int choice = input.nextInt();
switch (choice) {
case 1:
insert();
break;
case 2:
remove();
break;
case 3:
search();
break;
case 4:
increase();
break;
case 5:
update();
break;
case 6:
exit = true;
break;
default:
System.out.println("Invalid choice. Please try again.");
break;
}
}
}

public static void insert() {
if (size < 10) {
System.out.print("Enter a value to insert: ");
int value = input.nextInt();
List[size] = value;
size++;
} else {
System.out.println("Array is full. Cannot insert a new value.");
}
}

public static void remove() {
if (size > 0) {
System.out.print("Enter the index of the value to remove: ");
int index = input.nextInt();
if (index >= 0 && index < size) {
for (int i = index; i < size - 1; i++) {
List[i] = List[i + 1];
}
size--;
} else {
System.out.println("Invalid index. Please try again.");
}
} else {
System.out.println("Array is empty. Cannot remove a value.");
}
}

public static void search() {
System.out.print("Enter a value to search for: ");
int value = input.nextInt();
boolean found = false;
for (int i = 0; i < size; i++) {
if (List[i] == value) {
System.out.println("Value found at index " + i);
found = true;
}
}
if (!found) {
System.out.println("Value not found in the array.");
}

Steve works in human resources for a company with more than three thousand employees. He needs to send new insurance documents to each employee. Steve should _____.

A) use a digital ink pen to scan his handwritten notes from a meeting
B) send an e-mail to all employees and attach the insurance documents
C) call each employee and ask them to pick up the documents at his desk
D) create a presentation

Answers

The correct answer is B) send an email to all employees and attach the insurance documents. This is the most efficient and effective way for Steve to disseminate the insurance documents to all employees. It allows employees to access the documents electronically, at their convenience, and ensures that everyone receives the same information. Option A) using a digital ink pen to scan handwritten notes is not a viable option for distributing the insurance documents to all employees. Option C) calling each employee and asking them to pick up the documents at Steve's desk is also not practical, as it would be time-consuming and may not be convenient for all employees. Option D) creating a presentation is not relevant to the task at hand.

Other Questions
What is mental health and emotional health? morfologi kata kerja pasif The cost of 1 cup is $10. IF the cups come in sets of 5 and I have $170, how many cups I buy? The circle has a circumference of 628 inches. Find x. Use = 3.14. choisis un personnage du livre "un secret" de 20 lignes minimum et explique pourquoi il t'intresse Select the correct answer. Solve the quadratic equation by factoring. 9x -16 = 0 A group of sheep run in random directions to confuse a single predator. This is an example of which social behavior?O migratingO herdingO schoolingcooperative hunting George tallies up the transactions in his check register and comes up with a total balance of $221.57, but his bank statement says that his balance is $203.73. Which of the following are still outstanding?I. A $20.25 check to the floristII. A $14.29 check to the dry cleanersIII. A $38.09 check depositIV. A $19.05 money order deposita.I and IIIb.I and IVc.II and IIId.II and IV Which features of the Magna Carta influenced the Articles of Confederation? What caused the British to strictly limit the immigration of Jewish people to Palestine in the 1930s?resistance from the people living in PalestineOBthe issuance of the Mandate for PalestineCresistance from the Zionist movementDthe issuance of Balfour Declaration What is the multiplicative inverse of 3?A) -3. B) -1/3. C) 1/3 D) 3 what hairpiece has a base that covers the crown, occipital and nape area?a. fallb. braidc. switchd. chignon in The scarlet letter, and in the eyes of the narrator, Hester, Arthur, and Pearl are all victims of Gina is cleaning the tile floor in her kitchen. It takes her 20 minutes to clean 50 tiles.How many tiles can she clean in 1 minute? brainly in a paragraph, write a personal response to the passage from the pigman you have just read. what does the passage lead you to think A wall has a tiled mosaic consisting of 25 triangular tiles. Each tile has a base of 6 cm and a height of 8 cm. Find the area of the mosaic. An object is dropped from the edge of a cliff and is moving at 26.5 m/s just before it hits the ground. How high is the cliff Find the median: 86, 24, 65, 65, 24, 24 * one of the angels of a pairs of complementary angel is 50degree. find the ratio of the Paris of complementary angel. Did the Magna Carta lead to Parliament?