Exercise
1) Book Data
Create a book class to represent that a book contains
title
author
pages
year
type (for example: fiction, non-fiction)
Solution Link
2) Create a Circle Class
Attributes:
radius
diameter
Methods:
get_radius -OR- write a getter
get_diameter -OR- write a getter
get circumference
get area
make it printable
3) Inventory Items at a Store
An item in a store has:
Product Name
Product Price
Product Description
Product Quantity
Based on this list, create an item class for a store product.
4) Rock Paper Scissors
Create a RPS
class that contains attributes and methods to run a game of rock paper and scissors.
Solution Link
5) Stack
A stack
is a data structure that has two main features:
Push
-> adds an element to the collectionPop
-> removes the most recently added element
A common use of stack is the "undo" function. By removing the most recently made edits on a text file, we can go back to a previous state.
Stack's Attribute
Storage -> for simplicity, it will be a read only list attribute
Length -> tracking the size of the Stack
IsEmpty -> True when storage is empty
Stack's Methods
Push
Pop
Peek -> read-only view of what is at the top of the stack
All of stack operations are O(1)
with a space complexity of O(n)
Solution Link
Last updated