Write a function that reads stock share price at of N industries for M days as a two dimensional array and prints the diagonal price of the stock .
Question
Write a function that reads stock share price at of N industries for M days as a two dimensional array and prints the diagonal price of the stock.
Solution
Sure, here is a Python function that does that:
def print_diagonal_prices(stock_prices):
# Get the length of the 2D array
n = len(stock_prices)
# Loop through the 2D array
for i in range(n):
# Print the diagonal element
print(stock_prices[i][i])
This function takes a 2D list stock_prices
as input, where each row represents an industry and each column represents a day. It then prints the diagonal elements of this 2D list, which represent the stock prices of each industry on a certain day.
Here's how you can use this function:
# Define the 2D list of stock prices
stock_prices = [[10, 20, 30], [40, 50, 60], [70, 80, 90]]
# Call the function
print_diagonal_prices(stock_prices)
This will print:
10
50
90
This means that the stock price of the first industry on the first day was 10, the stock price of the second industry on the second day was 50, and the stock price of the third industry on the third day was 90.
Similar Questions
Calculate the standard deviation for each stock. (Do not round intermediate calculations. Round the final answers to 2 decimal places.)
Write C Program to Find the Sum of Each Row and Column of a 2x2 Matrix - 15 marksSample InputEnter the co-efficients of the matrix23 4580 97
Write C Program to Find the Sum of Each Row and Column of a 2x2 Matrix - 15 marksSample InputEnter the co-efficients of the matrix
Below is the table of values of a function. Write the output when the input is n.
Write a program to print the quotient and remainder on dividing sum of left-top to right-bottom diagonal by sum of right-top to left-bottom diagonal.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.