Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python def stocks_value(portfolio): return None if __name__ == '__main__' : portfolio1 = [( 'CAT' , 25, 43.50, 67.75), ( 'MSFT' , 100, 87.65, 82.50), (

Python

image text in transcribed

image text in transcribed

def stocks_value(portfolio): return None 
if __name__ == '__main__': 
 portfolio1 = [('CAT', 25, 43.50, 67.75), ('MSFT', 100, 87.65, 82.50), ('IBM', 35, 90.15, 92.97), ('APPL', 200, 175.00, 255.65)] portfolio2 = [('GOOG', 250, 325.86, 278.90), ('ABC', 115, 25.60, 29.85)] print('Testing stocks_value() for portfolio #1: ' + str(stocks_value(portfolio1))) print('Testing stocks_value() for portfolio #2: ' + str(stocks_value(portfolio2))) 
In addition to lists and dictionaries Python offers another type of collection called a tuple (pronounced "tupple" or "toople"). A tuple is a container for a fixed, immutable collection of values. This means that elements inside of a tuple cannot be changed or deleted. It also means that new items cannot be added to an existing tuple. In Python, a tuple is de noted using parentheses. Here are some examples of tuples: sizes small', 'medium', large', 'extra large ages (22, 29, 25, 30, 19, 24) info ('Jane Smith' 21, 3. 91) Note that we can mix data types within a single tuple. To access the elements of a tuple we can use bracket notation. For instance, the following code would print the string large on the screen: print (sizes [2]) Imagine we had a portfolio of stocks we purchased and then later sold. Here is an example: Symbol of Shares Purchase Price Selling Price 67.75 CAT 25 43.50 MSFT 100 87.65 82.50 IBM 35 90.15 92.97 APPL 200 255.65 175.00 We could represent these four stock transactions using a list of tuples: portfolio CAT' 25, 43.50, 67.75) ('MSFT', 100, 87.65, 82.50)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Joline Morrison, Mike Morrison

2nd Edition

? 061906448X, 978-0619064488

More Books

Students also viewed these Databases questions

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago