Question: def create _ list ( ) : # Create an empty list and prompt for the number of integers lst = [ ] num _

def create_list():
# Create an empty list and prompt for the number of integers
lst =[]
num_values = int(input("Enter number of integers in list: "))
for i in range(num_values):
value = int(input(f"Enter item #{i +1}: "))
lst.append(value)
return lst
def second_highest(lst):
# Create a deep copy of the list and sort it to find the second highest
sorted_lst = lst.copy()
sorted_lst.sort()
return sorted_lst[-2] # Return the second largest element
def make_positive(lst):
# Modify the list to make all elements non-negative
for i in range(len(lst)):
if lst[i]<0:
lst[i]= abs(lst[i])
def main():
# Create the list of integers
my_list = create_list()
print("My original list:", my_list)
# Find the second highest integer
second_largest = second_highest(my_list)
print(f"Second largest integer in list is {second_largest}")
# Make all elements in the list positive
make_positive(my_list)
print("My now positive list is", my_list)
if __name__=="__main__":
main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!