Business App Final

Ace your homework & exams now with Quizwiz!

Describe a class, an object, and the relationship between them Example

# Class definition class Person: def __init__(self, name, age): self.name = name self.age = age def get_name(self): return self.name def get_age(self): return self.age # Creating objects person1 = Person('John', 30) person2 = Person('Emma', 25) print(person1.get_name()) # Output: 'John' print(person2.get_age()) # Output: 25

Describe the relationship between a class in an object-oriented program and an entity in the real world Example

# Class representing a 'Person' entity class Person: def __init__(self, name, age): self.name = name self.age = age def greet(self): return f"Hello, my name is {self.name}, and I am {self.age} years old." # Creating an object representing a specific person person1 = Person('John', 30) print(person1.greet()) # Output: 'Hello, my name is John, and I am 30 years old.'

Describe how to convert lists/tuples to Dictionaries Example

# Converting a list to a dictionary keys = ['name', 'age', 'city'] values = ['John', 30, 'New York'] student_dict = dict(zip(keys, values)) print(student_dict) # Output: {'name': 'John', 'age': 30, 'city': 'New York'} # Converting a tuple to a dictionary student_info = (('name', 'John'), ('age', 30), ('city', 'New York')) student_dict = dict(student_info) print(student_dict) # Output: {'name': 'John', 'age': 30, 'city': 'New York'}

Dictionary Example

# Dictionary student = { 'name': 'John', 'age': 20, 'major': 'Computer Science' } print(student['name']) # Output: 'John'

Describe the OOP concept of inheritance. When is it appropriate to use inheritance? (Example)

# Superclass class Animal: def __init__(self, species): self.species = species def make_sound(self): pass # Subclass inheriting from Animal class Dog(Animal): def __init__(self, breed): super().__init__('Dog') self.breed = breed def make_sound(self): return 'Woof!' # Creating objects animal = Animal('Unknown') dog = Dog('Labrador') print(animal.species) # Output: 'Unknown' print(dog.species) # Output: 'Dog' print(dog.breed) # Output: 'Labrador' print(dog.make_sound()) # Output: 'Woof!'

UML Example

+-----------------+ | Person | +-----------------+ | - name: str | | - age: int | +-----------------+ | + get_name() | | + get_age() | | + set_name() | | + set_age() | +-----------------+

Describe the use of these clauses in SQL statements: FROM, WHERE, ORDER BY, and JOIN Example

-- FROM and WHERE clauses SELECT Name, Age FROM Student WHERE Major = 'Computer Science'; -- ORDER BY clause SELECT Name, Age FROM Student WHERE Major = 'Computer Science' ORDER BY Age DESC; -- JOIN clause SELECT Student.Name, Course.Course_Name FROM Student JOIN Enrollment ON Student.Student_ID = Enrollment.Student_ID JOIN Course ON Enrollment.Course_ID = Course.Course_ID;

Select, Insert, Update Example

-- SELECT statement SELECT Name, Age FROM Student WHERE Major = 'Computer Science'; -- INSERT statement INSERT INTO Student (Name, Age, Major) VALUES ('John', 25, 'Computer Science'); -- UPDATE statement UPDATE Student SET Age = 26 WHERE Name = 'John'; -- DELETE statement DELETE FROM Student WHERE Name = 'John';

Example Three tier

------------------------- | Presentation Tier | ------------------------- | Business Tier | ------------------------- | Database Tier | -------------------------

Relational Database Table Example

------------------------------------ | Student Table | ------------------------------------ | Student_ID (Primary Key) | | Name | | Age | | Major | ------------------------------------

Methods used for manipulating the items in a Dictionary

-dict.get(key, default): Returns the value associated with the key if it exists, otherwise returns the default value. -dict.keys(): Returns a view object containing all the keys in the dictionary. -dict.values(): Returns a view object containing all the values in the dictionary. -dict.items(): Returns a view object containing all the key-value pairs as tuples. -dict.pop(key[, default]): Removes the key and returns its value, or the default value if the key is not found. -dict.popitem(): Removes and returns the last inserted key-value pair as a tuple. -dict.clear(): Removes all items from the dictionary.

Describe a class, an object, and the relationship between them:

A class is a blueprint or template that defines the structure and behavior of objects. An object is an instance of a class, representing a real-world entity or concept. The relationship between a class and an object is that a class defines the common attributes and methods, while an object is a specific instance of that class with its own data.

Dictionary vs. List

A dictionary is an unordered collection of key-value pairs. Each key in a dictionary must be unique and immutable (e.g., string, number, tuple), and it is used to access its corresponding value. Dictionaries are enclosed in curly braces {} with key-value pairs separated by colons :.

Describe the organization of a relational database in terms of tables, rows, columns, primary keys, and foreign keys

A relational database is organized into tables, where each table represents an entity or concept. Rows in a table represent individual records or instances of the entity, and each column represents an attribute of that entity. Primary keys are unique identifiers for each row in a table, ensuring that each record is uniquely identified. Foreign keys establish relationships between tables, linking data from one table to another.

View Object and the associated Dictionary methods

A view object is a dynamic view of the dictionary's keys, values, or key-value pairs. View objects are returned by methods like dict.keys(), dict.values(), and dict.items(). Changes made to the dictionary are reflected in the view objects, and vice versa.

Describe how to access items when working with a dictionary of dictionaries, a dictionary of lists, or a list of dictionaries

Accessing items in dictionaries of dictionaries involves using multiple keys to navigate through nested dictionaries. Accessing items in dictionaries of lists involves using the key to retrieve the list and then accessing elements using list indexing. Accessing items in a list of dictionaries involves using list indexing to get a dictionary and then using keys to access specific values.

What is Agile? What is the Manifesto for Agile Software Development? What are its four main concepts?

Agile is an iterative and incremental approach to project management and software development, emphasizing flexibility, collaboration, and customer feedback. The Manifesto for Agile Software Development is a set of guiding values and principles that provide the foundation for Agile methodologies. The four main concepts of the Agile Manifesto are:Individuals and interactions over processes and tools.Working software over comprehensive documentation.Customer collaboration over contract negotiation.Responding to change over following a plan.

How does Agile compare to the Waterfall System Development Life Cycle (SDLC)?

Agile is characterized by flexibility, adaptability, and frequent iterations, allowing for changes and feedback throughout the development process. The Waterfall SDLC is a sequential and linear approach where each phase must be completed before moving on to the next, and changes are difficult to incorporate once a phase is completed. Agile focuses on delivering value early and often, while Waterfall emphasizes comprehensive planning and documentation before development starts. Agile encourages close collaboration between team members and stakeholders, whereas Waterfall tends to have more defined roles and formalized communication.

Describe the way an event handler works with a GUI component like a button

An event handler, also known as an event callback or event function, is a function that is executed when a specific event occurs on a GUI component. For example, when a button is clicked, the associated event handler is called to respond to the click event. Event handlers are registered with GUI components using the bind() method or by specifying them as command parameters when creating buttons or other widgets.

Describe the connection object, cursor object, and results set, including the methods associated with them

Connection Object: Represents a connection to a database and is used to establish a connection and manage transactions. Cursor Object: Provides methods to execute SQL statements and interact with the database, such as executing queries and fetching results. Result Set: The set of data returned by a SELECT query, represented as rows and columns.

Describe how Python is used to create a constructor, attribute, and method in a class, and how an object is created from a class

Constructor: A constructor is a special method named __init__() that initializes the object's attributes when the object is created. It is called automatically when an object is instantiated. Attribute: An attribute is a variable that belongs to a class or an object. It represents the state or data of the object. Method: A method is a function defined within a class that defines the object's behavior and can operate on its attributes. Object Creation: To create an object from a class, you simply call the class like a function, passing any required arguments to the constructor.

Describe how database exceptions are handled

Database exceptions occur when there are errors or unexpected conditions while interacting with the database. In Python, database exceptions are typically caught and handled using try-except blocks to gracefully handle errors. Common database exceptions include sqlite3.Error, pymysql.Error, psycopg2.Error, etc.

Date and Time objects compared

Date and time objects in Python support standard comparison operators like <, <=, >, >=, ==, and !=. Comparison is based on chronological order: earlier dates/times are considered smaller than later ones.

Describe the use of these clauses in SQL statements: FROM, WHERE, ORDER BY, and JOIN:

FROM: Specifies the table or tables from which the data should be retrieved. WHERE: Filters the data based on specified conditions, selecting only the rows that meet the criteria. ORDER BY: Sorts the result set based on one or more columns, either in ascending or descending order. JOIN: Combines rows from two or more tables based on a related column.

Describe getter/setter methods and properties

Getter and setter methods provide controlled access to private attributes and allow validation or modification of attribute values. Python also provides a property decorator to create getter and setter methods as if they were attributes

Describe what is meant by the identity, state, and behavior of an object

Identity: It is a unique identifier for an object, representing its memory address. In Python, you can get the object's identity using the id() function. State: It refers to the data or attributes of an object at a particular point in time. The state can change over the lifetime of the object. Behavior: It represents the actions or methods that an object can perform. The behavior is defined by the class and remains consistent for all instances of the class.

Describe public and private attributes in objects:

In Python, there are conventions for declaring attributes as public and private, although Python doesn't enforce strict access control like other languages. Public attributes are accessible from outside the class and are declared without any leading underscores. Private attributes are intended for internal use within the class and are declared with a single leading underscore _.

Describe the reason for creating a subclass of the ttk.Frame class when you're building a GUI:

In Tkinter, the ttk.Frame class provides a container widget with theming support, allowing you to create a frame with a consistent look across different platforms. By creating a subclass of the ttk.Frame class, you can define your custom frame with additional functionality or customization specific to your application's needs. Subclassing allows you to add methods, attributes, or custom behaviors to the frame while still retaining all the functionalities provided by the ttk.Frame class.

Describe the relationship between a class in an object-oriented program and an entity in the real world:

In object-oriented programming, a class is a blueprint or template that defines the structure and behavior of objects. An entity in the real world refers to a concrete object or concept that exists and has specific characteristics and behaviors. A class represents the abstract concept of an entity, defining its attributes and methods. When objects are created from a class, they become instances of that class, representing real-world entities with their own unique characteristics and behaviors.

Describe the OOP concept of inheritance. When is it appropriate to use inheritance?

Inheritance is a fundamental concept of OOP that allows a class (subclass) to inherit the attributes and methods of another class (superclass). Subclasses can extend the functionality of the superclass by adding new attributes and methods or overriding existing ones. It is appropriate to use inheritance when there is a relationship between two classes, and the subclass is a specialized version of the superclass.

Naive Time objects vs. Aware

Naïve time objects don't have information about the time zone and daylight saving time, whereas aware time objects have this information. Naïve date/time objects assume a default system time zone, which might lead to incorrect results when dealing with different time zones. To create an aware object, you can use the pytz module or set the time zone information explicitly using the tzinfo argument.

Describe the concepts of object composition and encapsulation

Object Composition: Object composition is a design principle where a class contains objects of other classes as attributes, allowing complex objects to be built by combining simpler ones. Encapsulation: Encapsulation is the concept of hiding the internal implementation details of a class from the outside world and providing access to class attributes and methods through public interfaces. It helps in data protection and modularity.

Describe the process of overriding a method from a superclass:

Overriding allows a subclass to provide its own implementation for a method that is already defined in the superclass. The method in the subclass must have the same name and signature (arguments) as the method in the superclass. When a method is called on an object of the subclass, the overridden method in the subclass is executed.

Describe the OOP concept of polymorphism

Polymorphism allows objects of different classes to be treated as objects of a common superclass. It allows the same method name to be used for different classes, and the appropriate method is called based on the object's actual type at runtime.

Describe how to convert lists/tuples to Dictionaries

Python provides various ways to convert lists or tuples into dictionaries. The list or tuple should contain elements in pairs, where the first element represents the key, and the second element represents the value

Datetime

Python's datetime module provides several methods and constructors to work with dates, times, and datetime objects. datetime class constructors: datetime(year, month, day[, hour[, minute[, second[, microsecond]]]]) date class constructors: date(year, month, day) time class constructors: time([hour[, minute[, second[, microsecond]]]])

Timedelta

Python's timedelta class represents a duration or difference between two dates or times. It allows you to perform arithmetic operations with date and time objects, such as addition and subtraction.

Describe the use of these SQL statements: SELECT, INSERT, UPDATE, and DELETE

SELECT: Used to retrieve data from one or more tables in the database. INSERT: Used to add new records or rows into a table. UPDATE: Used to modify existing records in a table. DELETE: Used to remove records or rows from a table.

Describe the five steps for designing an object-oriented program:

Step 1: Identify Objects and Their Relationships Identify the entities and concepts relevant to the problem domain. Determine the relationships between these entities, including inheritance, composition, and aggregation. Step 2: Define Classes and Their Attributes Create class definitions based on the identified objects and relationships. Define class attributes (data) and methods (behavior) that represent the characteristics of each class. Step 3: Implement the Classes Write code to implement the class definitions in a programming language like Python. Implement constructor methods, attributes, and methods in each class. Step 4: Create Objects Instantiate objects from the defined classes to represent individual entities or instances of the real-world concepts. Set the attributes of each object to specific values based on the problem context. Step 5: Interact with Objects Interact with objects by calling their methods and accessing their attributes. Use object-oriented principles like encapsulation, inheritance, and polymorphism to design an efficient and flexible program.

Describe how the grid() method is used to lay out the components in a frame

The grid() method in Tkinter is used to create a grid-based layout for organizing GUI components within a frame. Each component is placed in a specific row and column of the grid, and its size can be adjusted based on the available space and the content's requirements. The grid() method accepts parameters like row, column, rowspan, columnspan, sticky, etc., to control the component's position and behavior within the grid.

Describe the isinstance method

The isinstance() function is used to check if an object is an instance of a specific class or any of its subclasses. It returns True if the object is an instance of the specified class or False otherwise.

What are the main components of the Agile process?

The main components of the Agile process include: Product Backlog: A prioritized list of features, changes, and enhancements that need to be implemented in the project. Sprints/Iterations: Time-boxed periods (usually 1-4 weeks) during which the development team works on specific tasks from the product backlog. Sprint Planning: A meeting at the beginning of each sprint to select and prioritize backlog items for that sprint. Daily Stand-ups: Short daily meetings where team members share progress, discuss challenges, and plan their work for the day. Sprint Review: A meeting at the end of each sprint to demonstrate completed work to stakeholders and gather feedback. Sprint Retrospective: A meeting at the end of each sprint to reflect on the team's performance and identify areas for improvement. Continuous Integration and Continuous Deployment: Practices that involve integrating code changes frequently and deploying them to production in short cycles.

Describe the need for the mainloop() method of a tkinter root window in terms of the event processing loop:

The mainloop() method is a crucial part of the event-driven programming model used in GUI applications. It is responsible for creating an event processing loop, which continuously monitors for user input and events such as button clicks, mouse movements, and keyboard inputs. When an event occurs, the mainloop() method detects it and calls the corresponding event handler to respond to the event. Without the mainloop(), the GUI application would not be able to handle events and would become unresponsive

Describe the Python 'object' class and the str(), iter(), and next() methods

The object class is the base class for all other classes in Python. Every class in Python implicitly inherits from the object class. The __str__() method is used to represent the object as a string. It is called when using the str() function or printing the object. The __iter__() method allows an object to be iterable, meaning it can be used in a for loop. It should return an iterator object. The __next__() method is used in combination with __iter__() to provide the next element in the iteration.

Distinguish between the presentation tier, the database tier, and the business tier in a three-tier architecture:

Three-tier architecture is a design pattern that separates an application into three logical tiers: presentation, business, and database. Presentation Tier: Also known as the user interface (UI) tier. It is responsible for handling user interactions and presenting information to users. Includes GUI components, web pages, or mobile interfaces. Business Tier: Also known as the application logic tier or service layer. Contains the business logic and rules that process and manipulate data from the presentation tier. Interacts with the database tier to fetch or update data as needed. Database Tier: Also known as the data tier or data access layer. It is responsible for storing and managing data. Consists of a relational database or any other data storage system.

Describe a UML class diagram

UML (Unified Modeling Language) class diagram is a visual representation of the structure and relationships of classes in an object-oriented program. It consists of class boxes with attributes and methods, along with associations, inheritance, and multiplicity relationships between classes.

Describe the OOP concept of polymorphism Example

class Animal: def make_sound(self): pass class Dog(Animal): def make_sound(self): return 'Woof!' class Cat(Animal): def make_sound(self): return 'Meow!' def animal_sound(animal): return animal.make_sound() # Polymorphism in action dog = Dog() cat = Cat() print(animal_sound(dog)) # Output: 'Woof!' print(animal_sound(cat)) # Output: 'Meow!'

Describe the process of overriding a method from a superclass Example

class Animal: def make_sound(self): return 'Unknown sound' class Dog(Animal): def make_sound(self): return 'Woof!' # Overriding method in action animal = Animal() dog = Dog() print(animal.make_sound()) # Output: 'Unknown sound' print(dog.make_sound()) # Output: 'Woof!'

Describe the isinstance method Example

class Animal: pass class Dog(Animal): pass dog = Dog() print(isinstance(dog, Dog)) # Output: True print(isinstance(dog, Animal)) # Output: True (since Dog is a subclass of Animal)

Describe what is meant by the identity, state, and behavior of an object Example

class Car: def __init__(self, brand, model): self.brand = brand self.model = model def start_engine(self): print(f"{self.brand} {self.model} engine started.") car1 = Car('Toyota', 'Camry') car2 = Car('Honda', 'Civic') print(id(car1)) # Output: Unique memory address for car1 print(car2.brand) # Output: 'Honda' car1.start_engine() # Output: 'Toyota Camry engine started.'

Describe how Python is used to create a constructor, attribute, and method in a class, and how an object is created from a class Example

class Circle: def __init__(self, radius): self.radius = radius def calculate_area(self): return 3.14 * self.radius ** 2 # Creating objects circle1 = Circle(5) circle2 = Circle(7) print(circle1.calculate_area()) # Output: 78.5 print(circle2.radius) # Output: 7

Describe the concepts of object composition and encapsulation Example

class Engine: def __init__(self, horsepower): self.horsepower = horsepower class Car: def __init__(self, brand, model, engine): self.brand = brand self.model = model self.engine = engine def start_engine(self): print(f"{self.brand} {self.model} engine with {self.engine.horsepower} horsepower started

Describe the Python 'object' class and the str(), iter(), and next() methods Example

class MyObject: def __init__(self, data): self.data = data def __str__(self): return f'MyObject with data: {self.data}' def __iter__(self): self.index = 0 return self def __next__(self): if self.index < len(self.data): result = self.data[self.index] self.index += 1 return result else: raise StopIteration obj = MyObject([1, 2, 3]) print(str(obj)) # Output: 'MyObject with data: [1, 2, 3]' for item in obj: print(item) # Output: 1 2 3

Describe getter/setter methods and properties Example

class Person: def __init__(self, name, age): self._name = name self._age = age # Getter method def get_name(self): return self._name # Setter method def set_name(self, name): self._name = name # Property method for age attribute @property def age(self): return self._age @age.setter def age(self, age): if age >= 0: self._age = age person = Person('John', 30) print(person.get_name()) # Output: 'John' person.set_name('Mike') print(person.get_name()) # Output: 'Mike' person.age = 25 print(person.age) # Output: 25 person.age = -5 # Will not change the age since it is less than 0 print(person.age) # Output: 25

Describe public and private attributes in objects Example

class Person: def __init__(self, name, age): self.name = name # Public attribute self._age = age # Private attribute def get_age(self): return self._age person = Person('John', 30) print(person.name) # Output: 'John' print(person.get_age()) # Output: 30 print(person._age) # Valid, but should be avoided (conventionally private)

Dictionary of Lists

course_enrollments = { 'math': ['John', 'Emma', 'Michael'], 'science': ['Alice', 'Ethan', 'Olivia'] } # Accessing items in a dictionary of lists science_students = course_enrollments['science'] print(science_students) # Output: ['Alice', 'Ethan', 'Olivia']

Date and Time objects compared example

import datetime # Comparing date objects date1 = datetime.date(2023, 8, 1) date2 = datetime.date(2023, 8, 2) if date1 < date2: print("date1 is before date2") elif date1 > date2: print("date1 is after date2") else: print("date1 and date2 are the same") # Comparing time objects time1 = datetime.time(12, 30) time2 = datetime.time(13, 0) if time1 < time2: print("time1 is before time2") elif time1 > time2: print("time1 is after time2") else: print("time1 and time2 are the same")

Datetime Example

import datetime # Creating a datetime object dt1 = datetime.datetime(2023, 8, 1, 12, 30, 45) print(dt1) # Creating a date object d1 = datetime.date(2023, 8, 1) print(d1) # Creating a time object t1 = datetime.time(12, 30, 45) print(t1)

Timedelta Example

import datetime # Creating timedelta objects delta1 = datetime.timedelta(days=5, hours=3, minutes=15) delta2 = datetime.timedelta(weeks=2) # Using timedelta to perform arithmetic operations now = datetime.datetime.now() future_date = now + delta1 past_date = now - delta2 print("Now:", now) print("Future Date:", future_date) print("Past Date:", past_date)

Naive Time objects vs. Aware Example

import datetime # Naïve datetime object (no timezone information) dt_naive = datetime.datetime(2023, 8, 1, 12, 30, 0) print(dt_naive) # Aware datetime object with timezone information import pytz tz = pytz.timezone('America/New_York') dt_aware = datetime.datetime(2023, 8, 1, 12, 30, 0, tzinfo=tz) print(dt_aware)

Describe the connection object, cursor object, and results set, including the methods associated with them Example

import sqlite3 # Establishing a connection and creating a cursor conn = sqlite3.connect('example.db') cursor = conn.cursor() # Executing a SELECT query and fetching results cursor.execute('SELECT Name, Age FROM Student WHERE Major = ?', ('Computer Science',)) results = cursor.fetchall() for row in results: print(row) # Closing the cursor and connection cursor.close() conn.close()

Describe how database exceptions are handled Example

import sqlite3 try: conn = sqlite3.connect('example.db') cursor = conn.cursor() cursor.execute('SELECT Name, Age FROM Student') results = cursor.fetchall() for row in results: print(row) cursor.close() conn.close() except sqlite3.Error as e: print(f"Database Error: {e}")

Describe the way an event handler works with a GUI component like a button Example

import tkinter as tk def button_click(): print("Button clicked!") root = tk.Tk() button = tk.Button(root, text="Click Me", command=button_click) button.pack() root.mainloop()

Describe the reason for creating a subclass of the ttk.Frame class when you're building a GUI Example

import tkinter as tk from tkinter import ttk class CustomFrame(ttk.Frame): def __init__(self, parent): super().__init__(parent) # Custom initialization code here... # Creating the main application window root = tk.Tk() # Using the custom frame frame = CustomFrame(root) frame.pack() root.mainloop()

Describe the need for the mainloop() method of a tkinter root window in terms of the event processing loop Example

import tkinter as tk root = tk.Tk() # GUI components and event handling code here... root.mainloop() # Event processing loop starts

Describe how the grid() method is used to lay out the components in a frame Example

import tkinter as tk root = tk.Tk() label1 = tk.Label(root, text="Label 1") label2 = tk.Label(root, text="Label 2") label3 = tk.Label(root, text="Label 3") # Placing components in the grid label1.grid(row=0, column=0) label2.grid(row=0, column=1) label3.grid(row=1, column=0, columnspan=2) root.mainloop()

Methods used for manipulating the items in a Dictionary Example

student = { 'name': 'John', 'age': 20, 'major': 'Computer Science' } # Manipulating items student['age'] = 21 student['year'] = 3 print(student.get('year', 'N/A')) # Output: 3 print(student.keys()) # Output: dict_keys(['name', 'age', 'major', 'year']) print(student.values()) # Output: dict_values(['John', 21, 'Computer Science', 3]) print(student.items()) # Output: dict_items([('name', 'John'), ('age', 21), ('major', 'Computer Science'), ('year', 3)]) student.pop('major') print(student) # Output: {'name': 'John', 'age': 21, 'year': 3} student.clear() print(student) # Output: {}

View Object and the associated Dictionary methods Example

student = { 'name': 'John', 'age': 20, 'major': 'Computer Science' } keys_view = student.keys() values_view = student.values() items_view = student.items() print(keys_view) # Output: dict_keys(['name', 'age', 'major']) print(values_view) # Output: dict_values(['John', 20, 'Computer Science']) print(items_view) # Output: dict_items([('name', 'John'), ('age', 20), ('major', 'Computer Science')]) # Adding a new key-value pair to the dictionary student['year'] = 3 print(keys_view) # Output: dict_keys(['name', 'age', 'major', 'year']) print(values_view) # Output: dict_values(['John', 20

List of Dictionaries

students = [ {'name': 'John', 'age': 25, 'major': 'Computer Science'}, {'name': 'Emma', 'age': 22, 'major': 'Mathematics'} ] # Accessing items in a list of dictionaries emma_major = students[1]['major'] print(emma_major) # Output: 'Mathematics'

Dictionary of Dictionaries

students = { 'john': {'age': 25, 'major': 'Computer Science'}, 'emma': {'age': 22, 'major': 'Mathematics'} } # Accessing items in a dictionary of dictionaries john_major = students['john']['major'] print(john_major) # Output: 'Computer Science'


Related study sets

Ch 04 Milestones: Trust and Mistrust

View Set

Electrolyte Balance and Imbalance NCLEX QUESTIONS

View Set

W/L CH: 30 Central Nervous System Tumors

View Set

Deductive and Inductive arguments

View Set