Proactive Programmers
Repository | https://github.com/ProactiveProgrammers/www.proactiveprogrammers.com |
Copyright | Default |
Welcome!¶
Quote
"Ethical programming includes being honest about the extent to which you can be confident that your program is good, and adhering to quality control processes that ensure if a mistake has been made [...] it is found and rectified before it causes harm." Perdita Stevens in How to Write Good Programs
As they "act in anticipation of future problems, needs, or changes"1 proactive programmers ethically implement software in a fashion that is responsible to themselves, to the others in their team, and to the people who rely on their project. Always working to establish a confidence in their program's correctness, proactive programmers implement high-quality software that is designed, documented, tested, and maintained according to industry best practices.
Is this challenging? Yep! Will you make mistakes along the way to emerging as a proactive programmer? Of course! Are there many benefits to being a proactive programmer? Yes! If you want to learn more about proactive programming, you are invited study the proactive skills and complete the projects in data abstraction and discrete structures.
Are you nervous about getting started or afraid that becoming a proactive programmer will prove to be too overwhelming? Don't worry, you can rely on the team of programming experts who have crafted activities that will help you to hone your technical and professional skills. If you get stuck on this adventure you will find a welcoming community of like-minded learners who can answer your technical questions, make suggestions for improvement, and relate to your struggles.
Ready to put the PRO in your programming skills? Start your journey with one of these resources!
After installing cutting-edge Python development tools, learn the professional skills that support proactive programming.
After reviewing a strategy for how you can proactively learn to program, review the types of assignments that this site features.
After reviewing program building blocks, learn how to integrate, and study the performance of data structures and their functions.
Explore the fascinating connections between discrete mathematics and programming as you implement realistic Python programs.
Want to start a learning how to program? Launch your adventure with one of these projects!
After implementing a benchmarking program in Python, conduct an experiment to determine the fastest approach to finding the common items in a list.
After implementing a Python program that computes the numbers in the Collatz sequence, find which starting number yields the longest chain.
Ever wondered how fast a Python program can determine if an item exists inside of a list? Build a benchmarking framework and conduct an experiment to out!
After implementing a Python program reads in text files, use the set discrete structure to automatically analyze the text and visualize its structure use Venn diagrams.
Want to engage the proactive programming community? Check out these ways to get connected!
Have a valuable insight to share? Give feedback or report a bug in the site's writing or source code through the GitHub issue tracker.
Have a detailed question or need support with technical content on the site? Start a converation on the GitHub discussion forum.
Want to discuss the challenges you face as an emerging proactive programmer or have a brief question? Chat on our Discord server.
Not sure where to begin? Find learning opportunities in areas ranging from object-oriented programming to software testing.
Proactive Skills ↵
Introduction¶
Quote
"We are what we repeatedly do. Excellence, then, is not an act but a habit." Will Durant in The Story of Philosophy
Have you ever heard to quote "We are what we repeatedly do. Excellence, then, is not an act but a habit."? While many people often attribute this quote to Aristotle, it was actually written by Will Durant in The Story of Philosophy! Before you start working on the projects featured on this site, it is a good idea to pause to reflect on the proactive skills that you need to internalize as habits before you can confidently write high quality software. This site introduces both technical skills, like implementing and testing a program in Python, and professional skills, like effective communication and time management.
As expected, a proactive programmer must know how to use development tools like a text editor, a terminal window, and the Git version control system. With that said, you are probably wondering how effective communication skills and time management support the practice of proactive programming! The experience of many proactive programmers suggests that the ability to communicate with both team members and an instructor are skills that are as valuable as knowing how to install Python on your laptop.
Why is that the case? As an example, it is hard to "act[s] in anticipation of future problems, needs, or changes"1 if you are always running behind schedule on your programming projects. It also hard to be responsible to yourself, your team members, and the people who use the software you create if you can't communicate effectively to learn, for instance, what software you need to build, who will design and create the different system components, and how you should create your own parts of the system.
Let's dive into some of the technical skills that you will need as a proactive programmer!
Technical Skills ↵
Introduction¶
Quote
"What actually works is doing similar but subtly different things, paying attention to what works and what doesn't, and then changing behavior in response to that feedback to get cumulatively better." Greg Wilson in Teaching Tech Together
To become a proactive programmer you need to become comfortable with and then a master of a wide variety of technical skills that include using a text editor and a terminal window and testing and debugging your program. When faced with an array of technical skills that you need to master, it is worth asking: how do I get good at all of these skills? While there are a lot of skills that you will should develop as you emerge as a proactive programmer, it is exciting to report that there are some proven strategies towards mastering them!
Have you ever heard that, to master a skill, you primarily need to devote 10,000 hours to practicing it? While practice is, in fact, really important, it seems that the "10,000 hours rule" in a misinterpretation of the research of K. Anders Ericsson. So, what does help? Well, Greg Wilson writes in Teaching Tech Together that "what actually works is doing similar but subtly different things, paying attention to what works and what doesn't, and then changing behavior in response to that feedback to get cumulatively better."
Specifically, to master the technical skills introduced on this site you need to participate in deliberate practice that "requires both a clear performance goal and immediate informative feedback".1 In his post entitled Getting Good, author Brian Hogan explained deliberate practice similarly when he wrote that if you have a skill you want to get better at you must "practice every day", "get feedback", and "do more than you watch and read". Building on the bullet point from Teaching Tech Together, these are the steps you should take when using deliberate practice to proactively learn new technical skills:
-
Act on feedback from others: While attempting to install, configure, and use a program on your laptop (e.g., VS Code or Python), ask a more established programmer who has already successfully accomplished this task what they think of your setup and the approach that you took to create it. Next, listen carefully to their feedback and then attempt to improve your setup as needed, asking for clarification as appropriate.
-
Give feedback on the work of others: As you are installing, configuring, and learning how to use a software tool needed for proactive programming, offer constructive feedback to a peer who recently completed a similar step. Once you have shared your suggestions, ask both your peer and a more established programmer to evaluate the way in which you delivered the feedback and the quality of the feedback itself.
-
Give feedback to yourself: After you have regularly practiced a technical skill, such as implementing and testing Python programs, take time to observe your use of this skill and develop a critique of your own approach. After identifying areas for improvement, make a list of SMART goals that will enable you to more effectively put a specific technical skill into practice, follow your plan, and work to continually to improve.2
Keeping these ideas in mind, let's dive into the first technical skill!
-
See Merriam-Webster for the definition of Teaching Tech Together for more details about how to effectively learn technical skills. What practical steps can you take to best ensure that you can master the technical skills of a proactive programmer? ↩
-
See the article called How to write SMART goals for an overview of how to create SMART goals that are specific, measurable, achievable, relevant, and time-bound. In your view, what are the benefits of ensuring that your goals fit into the SMART paradigm? ↩
Using VS Code¶
Introduction¶
The team that creates and maintains the VS Code text editor describes it as "code editing redefined" and points out that it is "free" and "built on open source" and that it "runs everywhere". Sounds nice, huh? After you have reviewed the content on VS Code's web site, follow the instructions there to install in on the computer that you will use for proactive programming. Now, go ahead and take some time to customize your text editor so that it uses a color scheme that matches your style!
Extensions¶
To complete your setup of VS Code, please read about, install, configure, and practice using the following VS Code extensions! While some of the extensions in the following list are mandatory for you to become a successful proactive programmer who uses Python (e.g., the Python extension from Microsoft), others are optionally installed at your discretion if you think the would be helpful (e.g., Bookmarks from Alessandro Fragnani). Make sure that you install extensions in each of the following categories!
Python Programming¶
Collaborative Programming¶
- Use Live Share to Better Collaborate in VS Code
- Collaborate with Live Share in VS Code
- Remove Pair Programming with VS Code and Live Share
Git and GitHub¶
Okay, now that you have configured your text editor it is time to learn how to write technical documentation with VS Code!
Using Markdown¶
Introduction¶
Proactive programmers normally don't use Google Docs or Microsoft Word to edit either their source code or their technical documentation. Instead, you can use VS Code to write all of your documentation in a markup language called Markdown. Guess what? A significant amount of the content on this site was written in Markdown! You can learn some of the features of Markdown by studying this site's source code and reading the following resources that will help you to learn how to use Markdown for technical writing.
Features¶
Markdown offers several constructs that support technical writing, including the following:
- Inline source code samples
- Fenced source code block
- Nestable sections
- Ordered and unordered lists
- Links to images and web sites
A platform like GitHub can render Markdown into text that looks like you wrote it in a word processor! You can learn more about these constructs by checking these resources.
Resources¶
It is worth noting that the last tool in this list is called a "linter" because it can check for small mistakes in a programmer's technical writing. Many proactive programmers use linters in GitHub Actions to ensure that they don't write Markdown that does not display correctly when a web browser views the technical writing in a GitHub repository.
Okay, now let's learn how to install, configure, and use a terminal application!
Using Terminal¶
Introduction¶
The terminal window provides an interactive and text-based prompt that allows a proactive programmer to type commands that complete tasks like the following ones:
- Go into a directory
- Create or delete a directory or a file
- Delete a directory or a file
- Copy a file or directory to a new location
If you have previously used a graphical file browser other tools for manipulating the files and directory on your computer, then you may be wondering about whether or not there is any benefit to using a terminal window! While proactive programmers have different preferences and ultimately adopt the tools that best suit their professional needs, the experiences of many suggest that — after becoming accustomed to a terminal window — it is possible to complete common programming tasks more rapidly.
Depending on your operating system, you may already have a terminal window
installed on your development workstation. If you are using MacOS or Linux,
then you should search through the programs installed on your computer to see
if you already have a suitable terminal, such as iTerm
on MacOS and
gnome-terminal
on Ubuntu. If you are using Windows 10 Pro or Windows 10
Enterprise, then you may have a terminal window called cmd
or powershell
.
Regardless of which terminal window is on your computer, run it and then
explore the commands for completing the tasks listed above, like going into
and out of a directory and creating and deleting a file or a directory.
Once you have developed some proficiency with your computer's default terminal window, share your experiences with the other members of the proactive community! Along with sharing your favorite tips and tricks, you should get solicit feedback on how to improve your use of the terminal window. Depending on your operating system you may also want to try one one or more of the terminal windows suggested by the following articles:
- The Best Free Standalone Terminals for Windows 10
- Ten Best Alternatives for the MacOS Terminal App
- Top Seven Open Source Terminal Emulators for Linux
Do you have some suggestions on the best way to customize your terminal window? Share them with the members of the proactive community!
Using GitHub¶
Understanding Git¶
Git is a version control system that enables a proactive programmer to incrementally document and save their work on a project. In addition to installing Git on your computer you need to setup an account on GitHub! Before you do so, it is worth taking some time to read a tutorial on Automated Version Control. After you understand what version control is and why you should use it, you are ready to install Git on your computer and create and configure a GitHub account! To get started, please read Installing Git and follow the instructions for your computer's operating system. If you want to learn more about Git commands that you can use, make sure to read the Git Cheatsheet from GitHub.
The projects on this site expect you to use GitHub to receive starting source code and, if you are an Allegheny College student, submit your projects for assessment. As such, it is important for you to be able to securely communicate with the GitHub servers! In the remainder of these steps you will create an account on GitHub and ensure that you can securely communicate with the GitHub servers.
-
If you do not already have a GitHub account, then please go to the GitHub web site and create one, making sure that, if you are a student at Allegheny College, you use your
allegheny.edu
email address so that you can join GitHub as a student at an accredited educational institution. You are also encouraged to sign up for GitHub's "Student Developer Pack" at Student Developer Pack, qualifying you to receive free software development tools. Additionally, please add a description of yourself and an appropriate professional photograph to your GitHub profile. Unless your username is taken, you should also pick your GitHub username to be the same as Allegheny's Google-based email account. If you are not enrolled at Allegheny College, then you can create a GitHub account with any name you prefer. -
If you have never done so before, you must use the
ssh-keygen
program to create secure-shell keys that you can use to support your communication with GitHub. This task requires you to type commands in a program that is known as a terminal. Your terminal will display as a box into which you can type commands. If you have already installed your terminal and it runs commands correctly, then you may need to further installssh-keygen
if it is not already installed on your computer. -
After starting the terminal, you will need to type the
ssh-keygen
command in it. Follow the prompts to create your keys and save them in the default directory. That is, you should press Enter after you are prompted to "Enter file in which to save the key ... :
" and then type your selected passphrase whenever you are prompted to do so. Please note that a "passphrase" is like a password that you will type when you need to prove your identify to GitHub. What files doesssh-keygen
produce? Where does this program store these files by default? Before moving on to the next step, take time to read the About SSH documentation provided by GitHub. -
Once you have created your SSH keys, you need to upload them to GitHub. To accomplish this task you should read the article called Adding an SSH Key to Your GitHub Account. Depending on your operating system and the programs currently installed on your laptop, it is possible that the steps that you need to follow may be slightly different than those listed on this site!
-
To upload your SSH key, you must log into GitHub and look in the right corner for an account avatar with a down arrow. Click on this link and then select the "Settings" option. Now, scroll down until you find the "SSH and GPG keys" label on the left, click to create a "New SSH key", and then upload your SSH key to GitHub. Depending on your operating system, you can copy your SSH key to the clipboard by going to the terminal and typing a command like
cat ~/.ssh/id_rsa.pub
and then highlighting its output. Alternatively, you can load your SSH key into VS Code and copy its contents to the clipboard. When you are completing this step in your terminal, please make sure that you only highlight the letters and numbers in your key! If you highlight any extra symbols or spaces then this step may not work correctly. To complete this step, paste the key's contents into the GitHub text field in your web browser. -
Now that your SSH keys are uploaded to GitHub you should try to clone a GitHub repository to your computer and confirm that the keys are working as expected. You might want to clone the GitHub repository that hosts the source code for this web site. Or, you can clone another repository on GitHub that seems interesting to you! If you want to clone the repository that contains the source code for this web site, go to github/www.proactiveprogrammers.com and click the green button with the "Clone" label. After following the instructions you should run a command like
git clone git@github.com:ProactiveProgrammers/www.proactiveprogrammers.com.git
in your terminal window. If everything worked correctly then you should see the source code for this site on your computer! It is also worth pointing out that, if you cloned this site's GitHub repository, then you cloned a public repository and, once you start to clone private GitHub repositories, you will again need to confirm that your SSH keys are supporting secure communication correctly.
Note
If you are an emerging proactive programmer who is not enrolled in a Computer Science class at Allegheny College, you can still work on this web site's assignments! After you have setup Git and created a GitHub account you can, for instance, work on the Integer Squaring project, you would click the "Use this template" icon in the integer-squaring-starter GitHub repository and create your own version of the project's source code. Now, you will automatically get project feedback through GitHub Actions!
It is a good idea to further customize your configuration of Git! Although you might not need to apply all of the commands in the following tutorials, make sure to read them and carefully take those steps that are necessary for your computer and operating system.
Python Programming¶
Introduction¶
Before you attempt to install the Python programming language on your computer, it is worth taking time to build a mental model about what a Python program actually is and what happens when it runs on your computer. Sounds abstract, right? In a way, it is! But, building and regularly updating a mental model for Python programs will eliminate some of the confusion that arises when your program does something initially unexpected.
Notional Machine¶
The book called Teaching Tech Together summarizes, in twelve statements, a notional machine for the syntax, semantics, and behavior of a Python program. Please read the twelve components of the notional machine for Python and identify both the parts of it that you understand the best and those that are confusing. You can share your ideas with the proactive community and then clarify points that are confusing for others and receive feedback on your own points of confusion. Although you should develop an intuitive understanding of all twelve parts of the notional machine, let's review some of them now!
-
Every piece of data is stored in a two-part structure. The first part says what type the data is and the second part is the actual value: This means that we can think of the variables in a Python program as a "box" that has two regions in it. The first region stores the type of data (e.g., it is a
str
that stores character-based data consisting of letters and symbols) and the second region stores the actual data itself (e.g., the word"proactive"
could be stored inside of an variable of typestr
). -
Booleans, numbers, and character strings are never modified after they are created: This means that variables of type
bool
,int
, andstr
are immutable and thus they never change once they are created and stored in the memory of a Python program. Knowing that these variables do not change after creation will help you to avoid some fundamental misunderstandings that often lead to defects in your program and thwart your goal to becoming a proactive programmer. -
When code is executed, Python steps through the instructions, doing what each one tells it to in turn: This reveals that the Python programming language has an interpreter, called
python
, that you can use to run a Python program.1 Intuitively, the process of running a Python program involves the interpreter running each instruction and then following its control flow that shows which instruction to run next.
Installing Python¶
Now that you have an intuitive understanding of how a program written in the
Python programming language works, you are ready to install it on your own
computer! In his book Introduction to Computation and Programming Using
Python
John Guttag writes "By now, all of the
important public domain Python libraries have been ported to Python 3. Today,
there is no reason to use Python 2." Given this observation, this site
encourages you to install the most up-to-date Python 3 version on your computer
and ensure that it is invoked by the running command python
in your terminal
window. To get started with the installation of Python, you should review
tutorials like these:
- Setting Up Python on Windows
- Python 3 Installation and Setup Guide
- How to Install Python 3 and Set Up a Local Programming Environment on Windows 10
If you are learning to become a proactive programmer while using a computer
running either a Linux or a MacOS, then you should install Python 3.10 by using
either the tool called Pyenv or the tool
called asdf. If you are instead using a computer that
runs Windows 10, then you can attempt to install Python 3.10 using either
Pyenv-win or the installation
instructions in one of the aforementioned articles. Please remember that, if
you are installing Python on Windows it should either be a complete version of
the most recent version of Python (i.e., Python 3.10) and it should be
executable through the use of the python
command in your terminal. You can
confirm that you have the correct version of Python installed on your computer
by typing python --version
in your terminal window and then looking for the
expected version number. It is important that you do not install and attempt to
use any older versions of this programming language than Python 3.8.
Now that you have Python 3.10 installed on your computer you should complete
all of the steps in the tutorial called Getting Started with Python in VS
Code.
When you complete this tutorial make sure that select your installed version of
Python through VS Code and write, run, and debug a "Hello World!" program
written in Python. Along with confirming that you can run the "Hello World!"
Python program through VS Code, you should ensure that you can run the same
program in your terminal window by using the python
program.
Depending on your computer's hardware, operating system, and supporting software, you will find numerous tutorials that will explain how to install all of the software development tools needed for proactive programming. For instance, Ian Wootten's article called Setting Up a New M1 mac for Development explains, among many other steps, how to install Python on a laptop running MacOS. Regardless of which approach you adopt for installing Python on your computer, make sure that you take careful notes at each step and plan for having to repeat specific steps until you can confirm that you can implement and run a basic program on your computer. If you get stuck or if you have advice to share, make sure that you connect with the other members of the proactive community!
Now you are ready to install a tool that supports Python packaging!
-
Many proactive programmers benefit from using pyenv on either MacOS or Linux and pyenv-win on Windows 10 to manage the installation of the Python interpreter on their computers. It is worth noting that these programs will often install the Python programming language under the name
python
and not, for instance,python3
. ↩
Python Packaging¶
Installing Poetry¶
It is common for a proactive programmer to run their Python programs in a
virtual environment that contains isolated versions of all the packages on which
a specific program depends. Although there are many different ways to package a
Python program and manage its dependencies, a new tool called
Poetry offers a flexible and easy-to-use approach.
Bearing in mind that the installation instructions for Poetry vary depending on
whether your computer runs Windows, MacOS, or Linux, follow the installation
instructions in the Poetry Documentation to
ensure that the poetry --version
command displays the expected output in your
terminal window.
Using Poetry¶
Once you have installed Poetry, you should complete a tutorial called Building a Package where you can learn how to leverage Poetry to create a command-line application with the Typer package! It is worth noting that this tutorial will ask you to write Python source code. If you are not yet familiar with the Python programming language you can copy and paste the code from the tutorial to the appropriate file that you are editing with VS Code. That is, if you are getting started as a proactive Python programmer you should focus on learning how to use Poetry and concentrate less on learning the Python language. As you complete the tutorial, make sure that you consider the following commands in Poetry:
poetry new
: creates a new Poetry projectpoetry add
: adds a new dependency to a Poetry projectpoetry install
: install all dependencies for a Poetry projectpoetry shell
: enters into a shell containing all dependenciespoetry run
: runs a program in a virtual environmentpoetry build
: build a packaged version of the Poetry project
Package Installation¶
Please note that, at least for now, you don't need to focus on learning how to publish the tutorial package to the Python Package Index! With that said, if you are interested in doing so, you should now be able to install your program with either pip or pipx and run it as a stand-alone executable. If you get stuck on the use of either Poetry or Typer, make sure that you ask for help from the other members of the proactive community.
Using GatorGrader¶
Introduction¶
The projects on this web site integrate the
GatorGrader tool so that an
emerging proactive programmer can receive rapid feedback in either a GitHub
Actions build or by running an assessment tool on their computer. Since each
project on this site overviews the checks that GatorGrader runs, the purpose of
this documentation is to explain how to run GatorGrader through the use of
GatorGrade. To install the
GatorGrade program you need to, after first installing the most recent version
of Python, install the program called Pipx.
This program will make it easy for you to install GatorGrade through the use of
the command pipx install gatorgrade
. If you are in the home directory of a
specific project described on this site you can type the command gatorgrade
--config config/gatorgrade.yml
to run all the automated assessments for the
project.
Next Steps¶
Before you start to learn more about the professional skills of a proactive programmer, make sure that you review the introduction to these technical skills. Have you become comfortable with, for instance, acting on feedback from others, giving feedback to your colleagues, and giving feedback to yourself? Make sure that you continue to practice all of these technical skills, participating in the proactive community by sharing your ideas for improving this content and helping others to master each software tool!
Ended: Technical Skills
Professional Skills ↵
Introduction¶
Please check back later for information about the relevant professional skills!
Effective Communication¶
Please check back later for information about methods for effective communication!
Time Management¶
Please check back later for information about effective methods for time management!
Reading Documentation¶
Please check back later for information about how to read technical documentation!
Ended: Professional Skills
Ended: Proactive Skills
Proactive Community ↵
Introduction¶
Quote
"The secret to good documentation is to write it while you're writing the code. You are your first audience. Explain what you're doing to yourself. Future you will thank you!" Victoria Drake in How to Write Good Documentation
Since programming is difficult, it is common to become stuck and find that you need help to solve your current technical challenge. Even though getting stuck on a programming problem can be frustrating, the good news is that there are significant number of great resources that can help you to solve technical problems. In addition to sites like Stack Overflow, there are many informative blog posts written by experts who took to heart Victoria Drake's reminder that "[t]he secret to good documentation is to write it while you're writing the code. You are your first audience. Explain what you're doing to yourself." This means that the community of proactive programmers can, as a "second audience", benefit from the wide variety of technical posts on personal and company blogs. Here is an exciting thought to consider: after investing the time to become a proactive programmer you will have the knowledge and skills needed to deploy your own web site featuring articles in which you share what you learned when you overcame a tricky technical challenge!
The remainder of this section overviews a few of the external communities offering resources that can help a proactive programmer grow in their technical and professional skills. Please bear in mind that many of these communities provide both technical and professional development resources! It is also worth noting that the lists in the following sections are only starting points for your technical and professional growth. If you have some ideas for improving these lists of resources you can share them in the GitHub Issue Tracker or in the GitHub Discussions Forum!
Technical Community¶
Quote
"Everyone is welcome. You are not an imposter. No matter who you are or where you are on your path of being a developer — this community is a safe place for you to hang your hat and call home. All you have to do is take the first step." Changelog Editors in Changelog Developer Community
Looking to "level up" your technical skills as you emerge as a proactive programmer? Do you want to engage with a community of experts who can answer your questions and provide support? Do you have some technical wisdom that you want to share with others? The good news is that there are many different online communities that are designed for proactive programmers — the trick is finding the best ones and avoiding those that are toxic!
The following lists offer a starting point for the online programming communities, independent contributors, and audio podcasts that offer communities with top-notch technical resources. As the Changelog Editors in their Changelog Developer Community write "All you have to do is take the first step." So, go ahead and take the first step by checking out these communities, contributing when you can, and reporting back about what you find!
Don't forget, if you have ideas for improving these lists of resources you can share them in the GitHub Issue Tracker or in the GitHub Discussions Forum! Finally, did you notice that each page on this site can be edited through a pull request on GitHub? (Hint: look for the edit icon that displays as a pencil at the top right of every page on the site). This means that you can propose an edit to this page if you have a cool technical community to share!
Programming Communities¶
-
Real Python helps people to "learn Python programming, by example" and is useful for learners in courses on this site that require Python programming. The site features up-to-date technical articles with source code examples, diagrams, and illustrations.
-
Reddit is a discussion forum that hosts communities that devoted to many different areas. While this platform hosts less-than-stellar content, some communities are welcoming and provide thoughtful assistance for those facing technical challenges.
-
Stack Overflow is a question and answer site that hosts communities in many technical and professional areas. After reading a question, evaluate the quality of different answers and then try a solution to see if it solves your technical challenge!
Independent Contributors¶
-
Victoria Drake regularly shares blog posts that explore a variety of technical issues. Even if a specific post focuses on a technology that a learner is not currently using, it will likely share beneficial tips, tricks, and ways of thinking.
-
Gergely Grosz writes under the name "The Pragmatic Engineer" and shares numerous experiences that will help you to become a better programmer. Even if you are not an engineering manager you will find these posts interesting and thought provoking.
-
Ines Montani shares articles and videos that explain how to do natural language processing (NLP) in with the Python programming language. Even if you are not working in NLP, you will find the lessons in these posts informative and helpful.
Audio Podcasts¶
-
Changelog offers multiple free podcasts, including "The Changelog" podcast featuring "Conversations with the hackers, leaders, and innovators in the software world".
-
Software Engineering Daily features a daily podcast episode that interviews technical leaders and explores "the world through the lens of software".
-
Talk Python to Me offers interviews with the innovators in the field of Python programming, now in both an audio and live stream format.
Professional Community¶
Check back for references on how to build your professional skills!
Our Community¶
The proactive programmers community offers several ways in which you can grow in your technical skills. Try out the following resources and let us know what you think!
-
GitHub Issue Tracker allows you to, for instance, offer feedback on this site and report a defect in the source code examples that it features. To get started, log into your GitHub account and click the green button called "New Issue".
-
GitHub Discussions Forum gives proactive programmers the opportunity to ask and answer questions about the projects on this site. Upon completion of a discussion you can mark the accepted answer and help out others who face the same challenge. To get started, log into your GitHub account and click the "New discussion" green button.
-
Proactive Programmers Discord Server provides a way for members of the proactive community to use text and video to chat with each other. To get started, click the link and accept the invitation to join the community. After you have setup your account and connected it to your email address, you can start to participate in the discussion.
-
Allegheny College Computer Science Discord Server provides a way for students who are studying computer science at Allegheny College to use text and video to chat with each other. To get started, click the link and accept the invitation to join the community. After you have setup your account and connected it to your email address, you can start to participate in the discussion in the public channels. You should also ask your instructor to add you to any relevant course channels.
Sometimes you may not be sure which community forum you should use! Here is some advice for you to consider when facing this dilemma. You should use the community forum that best connects to your situation, as illustrated with the following examples.
-
If you have a detailed technical question or need technical support with content on Proactive Programmers, then you should ask it on GitHub Discussions Forum.
-
If you have a quick technical question about the content on Proactive Programmers, then you should ask it on the Proactive Programmers Discord Server.
-
If you want to hang out or discuss the challenges you face as you become a proactive programmer, then you should go to the Proactive Programmers Discord Server.
-
If you want to share or receive career advice with other proactive programmers, then you should go to the Proactive Programmers Discord Server.
-
If you are a student studying computer science at Allegheny College and you want to communicate with your instructor or the students in your department, then you should go to the Allegheny College Computer Science Discord Server.
-
If you want to offer feedback about the content on Proactive Programmers, then you should create an issue in the GitHub Issue Tracker.
-
If you want to report a bug in either the source code or the written content on Proactive Programmers, then you should create an issue in the GitHub Issue Tracker.
Ended: Proactive Community
Proactive Learning ↵
Introduction¶
Quote
"Learning results from what the student does and thinks and only from what the student does and thinks. The teacher can advance learning only by influencing what the student does to learn." Herb Simon quoted in Solving a Teaching Problem
Herb Simon is quoted in Solving a Teaching Problem as saying that "learning results from what the student does and thinks and only from what the student does and thinks. The teacher can advance learning only by influencing what the student does to learn." This means that if you want to learn how to become a proactive programmer then you must take on challenging programming tasks! This site's projects site will help you to gain the knowledge and skills of proactive programming as you "learn by doing".
How challenging should the projects be? How many projects do you need to complete to learn to program? Although it is difficult to precisely answer these questions for each person, it is fair to say that learning to program involves a significant amount of failure. In fact, studies of machine learning algorithms that learned to complete complex tasks suggest that they learned better when they failed in their efforts about 15% of the time.1 Even though you are not an algorithm, it is worth bearing in mind that failure through a trial-and-error process is a normal and beneficial — albeit frustrating! — part of becoming a proactive programmer.
Yet, how much failure is too much? Michael Hilton likes to tell his students "it is okay to experience failure as long as you are learning" and that you should contact him "if you are failing and not learning". Since you might not be Michael's student, you probably should not contact him if you face challenges! But, if you have a detailed question about any of the projects on this site, you are invited to post in the GitHub Discussions Forum. Or, if you want to have a quick discussion about a technical topic then you can ask it in the Allegheny College Computer Science Discord Server (for Allegheny College students) or the Proactive Programmers Discord Server (for all learners).
Before you dive into the projects on this site, let's first consider how different types of learning exhibit different levels of cognitive difficulty and how the projects you complete will be assessed depending on your learning context.
-
Check out the paper The Eighty Five Percent Rule for Optimal Learning that Robert Wilson published as the lead author. After reading this article, do you think that the behavior of machine learning algorithms can surface insights about human learning? ↩
Bloom's Taxonomy¶
Quote
"A learning objective describes how the learner will demonstrate what they have learned once they have successfully completed a lesson. More specifically, it has a measurable or verifiable verb that states what the learner will do and specifies the criteria for acceptable performance." Greg Wilson in Teaching Tech Together
As you become a proactive programmer, it is important for you to know how the projects on this site were designed in terms of the learning type that they support and the complexity of the tasks they ask you to complete.1 While you may be thinking that this is only a topic for teachers, it turns out that knowing the basics of this taxonomy is also helpful for learners! For instance, this site features assignments and learning objectives that are connected to specific levels in this taxonomy.
Don't forget that these levels are organized from those that have the least amount of cognitive complexity to those that have the most. Ready to see examples of programming projects and how they connect to Bloom's taxonomy? Using direct quotes from Greg Wilson's book called Teaching Tech Together, let's describe the taxonomy's "levels" and "verbs" and give task examples.2 It's worth noting that many of the examples in this list will require the design and implementation of a program, which is normally the domain of the creating level. Since the study of proactive programming often requires the creation of source code, this task is supported with instructor-provided programs at less difficult levels and done by the learner when more cognitive challenge is appropriate.
-
Remembering: "Exhibit memory of previously learned material by recalling facts, terms, basic concepts, and answers."
- Keywords: recognize, list, describe, name, find.
- Example: Run a program that performs a numerical calculation, find the iteration construct used in the program, observe its output when run in the terminal window, and use a text editor to describe both the output and why the program produces it.
-
Understanding: "Demonstrate understanding of facts and ideas by organizing, comparing, translating, interpreting, giving descriptions, and stating main ideas."
- Keywords: interpret, summarize, paraphrase, classify, explain.
- Example: After running a program that performs the conversion of temperature values, organize it into separate functions with descriptive documentation and explain how the functions work together to produce the output observed when it is run.
-
Applying: "Solve new problems by applying acquired knowledge, facts, techniques, and rules in a different way."
- Keywords: build, identify, use, plan, select.
- Example: Leveraging previously acquired knowledge about file input and parsing, select from existing functions to implement a program that iteratively searches a contact database for details about the individuals in someone's professional network.
-
Analyzing: "Examine and break information into parts by identifying motives or causes; make inferences and find evidence to support generalizations."
- Keywords: compare, contrast, simplify.
- Example: After implementing a program that features multiple ways to sort a list input from a file, compare and contrast the efficiency and implementation effort associated with each approach, attempting to understand the trade-offs evident in each one.
-
Evaluating: "Present and defend opinions by making judgments about information, validity of ideas, or quality of work based on a set of criteria."
- Keywords: check, choose, critique, prove, rate.
- Example: After defining the assessment criteria for a program's design, implementation, and user interface, create and evaluate a software tool that computes and visualizes the numbers in the Collatz sequence.
-
Creating: "Compile information together in a different way by combining elements in a new pattern or proposing alternative solutions."
- Keywords: design, construct, improve, adapt, maximize, solve.
- Example: After collecting information about the efficiency of different ways to uniqify a list, engineer a benchmarking framework that can run experiments to evaluate each approach. As the use of these benchmarks aids the identification of the best method, adapt each uniqifier so that it offers the best possible efficiency for a variety of inputs.
Okay, let's explore how the types of assignments that you will complete are connected to these levels of learning in Bloom's taxonomy!
-
See Robert Talbert's article Re-thinking Bloom's Taxonomy for Flipped Learning Design for a description of Bloom's taxonomy and how it aids the design of courses. In the context of programming, what level of the taxonomy is most exciting for you? ↩
-
Check out Greg Wilson's book called Teaching Tech Together for lots of great ideas on how to teach programming to different types of learners. How could ideas from this book could be further applied to improve this learning platform? ↩
Assignment Types¶
Quote
"The magic of myth and legend has come true in our time. One types the correct incantation on a keyboard, and a display screen comes to life, showing things that never were nor could be." Frederick P. Brooks, Jr. in The Mythical Man-Month
The book called The Mythical Man-Month, written by Frederick P. Brooks, Jr., contains the observation that "the magic of myth and legend has come true in our time. One types the correct incantation on a keyboard, and a display screen comes to life, showing things that never were nor could be." Wow, that makes programming sound really exciting! And, it really is as enervating as Frederick P. Brooks, Jr. makes it out to be. With that said, it can be overwhelming — and even counter-productive — for an emerging proactive programmer to start their journey by aiming to complete a major software project.
This site teaches proactive programming through three different types of programming projects, each of which is connected to two unique levels in Bloom's Taxonomy and therefore designed to develop your programming knowledge and skills in a systematic and scaffolded fashion.
-
Source Code Surveys connect to the remember and understanding levels of Bloom's taxonomy and invite learners to build a basic understanding of the building blocks of programs. Aimed at helping you to remember and understand how programming language constructs and a program's functions work, these projects ask you to run a program, observe its output, and describe its source source through technical writing.
-
Programming Projects connect to the applying and analyzing levels of Bloom's taxonomy and encourage learners to complete programming tasks designed to ensure that they can effectively build a program by comparing and contrasting different solutions and picking the best one for a given problem.
-
Engineering Efforts connect to the evaluating and creating levels of Bloom's taxonomy by asking learners to design, implement, test, and document programs that innovatively solve a problem. These projects help you to hone the skills of proposing, creating, assessing, and improving a complete software product.
Okay, sometimes the lines blur between these three types of assignments! With that said, it should be clear that a source code survey is very different than an engineering effort in that the former requires a learner to run a program and observe its output while the later asks a person to create and evaluate a complete program.
It's also worth noting that, for this purposes of this site's projects, a programming project normally involves the implementation and testing of fewer (and often less complex) source code lines than the program created as part of an engineering effort. Since projects in the engineering effort category focus on the creation and evaluation of programs, they also call for learners to complete technical writing tasks that are more thorough than those that are a part of either a programming project or a source code survey.
Still a little confused? Unconvinced that this focus on proactive learning is important? Don't give up until you complete some projects in fields like data abstraction and discrete structures! Also, don't forget: if you have some ideas for improving this content you can share them in the GitHub Issue Tracker or in the GitHub Discussions Forum.
Okay, now we can learn more about how these types of assignments will be assessed!
Assessment Strategy¶
To ensure that proactive programmers can effectively grow in their knowledge of software engineering as they study topics such as data abstraction and discrete structures, the projects that they complete will be receive rapid and frequent feedback, in adherence to the grading principles set forth by Robert Talbert. Specifically, the team of proactive programming experts will conduct assessments with these principles in mind.1
- Clearly Defined Standards: All projects will have a specification that clearly defines the characteristics of acceptable program source code and technical writing.
- Helpful Feedback: Project feedback will offer actionable suggestions for ways to better ensure that a source code or technical writing more fully adheres to the specification.
- Scores Suggest Progress: The scores assigned to a project will offer meaningful insight into the progress that a proactive programmer made to more fully meet the specification.
- Reattempts without Penalty: All projects will have a completion period during which a proactive programmer may repeatedly attempt to meet the specification without penalty.
Quote
"Developers came together from all corners of the world to innovate, find connection, and solve problems." GitHub in The State of the Octoverse
To support the assessment of projects in adherence to these principles, the team of proactive programming experts will leverage several software platforms and tools. All learners will complete all of their work through an industry-standard platform called GitHub. If they have not done so already, learners should create a free GitHub account. They will use this account and the GitHub repositories associated with it to receive starter materials and submit the final version of each assignment.
All learners at will receive rapid feedback on their work through a tool called GatorGrader. The instructor will define GatorGrader checks for each type of assignment. A learner's job will be to use a programming language, like Python, to implement a complete solution that passes all of the GatorGrader checks. Learners should also complete writing tasks that demonstrate their knowledge of the technical knowledge and skills developed as part of an assignment. In addition to running the GatorGrader tool on their laptop, learners will see the results from running GatorGrader checks in the continuous integration environment called GitHub Actions that is accessible for a GitHub repository.
A learner will receive a separate GitHub repository for each project on this site. Each of these GitHub repositories will have a pull request called "Feedback" through which a learner will receive feedback from the team of proactive programming experts who will assess their work. Moreover, each assignment type has its own assessment strategy!
Note
Learners who are not enrolled at Allegheny College are invited to complete all of the assignments on this site. With that said, those learners who are not at Allegheny College will not receive expert feedback on each of their assignments. Since these individuals will not be members of the Allegheny College GitHub Enterprise, they will need to work in adherence to the restrictions for their current GitHub plan. With that said, learners not enrolled at Allegheny College have free access to all of the assignments on this site! They can also create a GitHub repository for each project that completely integrates with an automated assessment tool designed to give them rapid feedback about the correctness of their solution. Finally, all learners are invited to join this site's Discord Server and discuss each of the assignments!
Engineering Efforts¶
Leveraging the principles of specification-based grading, the grade that a learner receives on an engineering effort will be based on whether or not it meets the standards for technical work in the field of computer science. Instead of receiving a single numerical or letter grade for this assignment, the grade for an engineering effort will have these parts:
-
Percentage of Correct GatorGrader Checks Ranging Between 0 and 100: The submitted program source code must pass all of GatorGrader's checks by, for instance, ensuring that it produces the correct output and has all of the required characteristics. The technical writing must pass all of GatorGrader's checks about, for instance, use of the required Markdown language features for technical writing. For this component of an engineering effort's grade, the project will receive a percentage, ranging from 0 to 100, that corresponds to the percentage of GatorGrader checks that pass inside of the project's last before-the-deadline GitHub Actions build.
-
Proactive Programming Skills of Either or : An engineering effort will also receive a checkmark grade when the contents of its GitHub repository reveal the mastery of the technical knowledge and skills developed during the completion of the project. This assessment will evaluate aspects of the project including, for instance, the use of accurate and succinct source code comments and Git commit messages. This assessment will also include an evaluation of the correctness and efficiency of the submitted Python source code.
-
Technical Writing Skills of Either or : The responses to the technical writing questions will receive a checkmark when they reveal a mastery of technical writing skills. To receive a checkmark grade, the submitted writing should have correct spelling, grammar, punctuation, and formatting in addition to following the rules of the Markdown language. The technical writing will further qualify for a checkmark grade if the build report from GitHub Actions reveals no mistakes in the technical writing. Finally, writing that is technically accurate will qualify for the checkmark grade.
-
Professional Skills of Either or : An engineering effort will receive a checkmark grade when the contents of its GitHub repository reveal the mastery of professional skills such as the ability to find, leverage, and reference technical documentation and source code examples. A project will further quality for this checkmark when it contains evidence that the person who submitted it reflected on their experiences when completing the project, connected the project to their prior work, and made actionable plans for continued improvement as a proactive programmer.
Programming Projects¶
Again leveraging the principles of specification-based grading, the grade that a learner receives on a programming project will be based on whether or not it meets the standards for technical work in the field of computer science as evidenced by:
- GitHub Actions Build Status of Either or : A programming project will receive a checkmark grade if the last before-the-deadline build in GitHub Actions passes and a appears in the GitHub commit log instead of an . The build status reported by GitHub Actions will only be a if the source code and technical writing in the GitHub repository pass all of the checks that were automatically executed in GitHub Actions.
Source Code Surveys¶
Again leveraging the principles of specification-based grading, the grade that a learner receives on a source code survey will be based on whether or not it meets the standards for technical work in the field of computer science as evidenced by:
- GitHub Actions Build Status of Either or : A source code survey will receive a checkmark grade if the last before-the-deadline build in GitHub Actions passes and a appears in the GitHub commit log instead of an . The build status reported by GitHub Actions will only be a if the source code and technical writing in the GitHub repository pass all of the checks that were automatically executed in GitHub Actions.
Advance Feedback¶
Learners at Allegheny College who wish to receive feedback on their work for any assignment should first open an issue on the issue tracker for their assignment's GitHub repository, giving an appropriate title and description for the type of feedback that they would like the instructor to provide. After creating this issue, they will see that GitHub has created a unique web site that references it. To alert the instructor to the issue's creation and that you want feedback on your work, please send it to him by a Discord direct message at least 24 hours in advance of the project's due date. After the instructor responds to the issue in GitHub, please resolve all of the stated concerns and participate in the discussion until the project meets its specification and the issue is closed.
Assessment Delivery¶
The instructor invites learners to incrementally complete all of the learning objectives for an engineering effort, programming project, and source code survey. As long as a learner's work passes all of the GatorGrader checks before an assignment's deadline, they will receive full credit for that part of an assignment's assessment. After the deadline for project submission, all assessments for a project will be reported through a learner's GitHub repository using messages in the GitHub repository's commit log, issues raised in the issue tracker, and comments on the "Feedback" pull request in the GitHub repository.
Assignment Discussion¶
Learners who wish to receive feedback on their work for any assessed assignment should ask questions in the same region of Github where the instructor shared the assignment's final assessment. For example, if the instructor shares the grade in a pull request in the repository for an engineering effort, then you should ask questions about your grade in that pull request, bearing in mind the need to @-mention the instructor in the body of your comment. Learners can continue to discuss the graded assignment with the instructor until they understand all the technical topics developed as part of the project.
Note
Before you continue reading the remainder of the assessment strategy it is worth pausing to remember that the instructor will give advance feedback to any learner at Allegheny College who requests it through GitHub and Discord at least 24 hours before the project's due date! Seriously, did you catch that? This policy means that you can thoroughly understand the ways to improve your project before its final assessment!
Grade Calculation¶
The instructor will convert the specification-based grades that a learner received to a numerical grade for each type of assignment. The following example illustrates the calculation of a grade under the simplifying assumption that there are three of each type of assignment with the grade(s) given next to the name of the assignment:
Engineering Efforts¶
- Assignment One: 100%, , ,
- Assignment Two: 81%, , ,
- Assignment Three: 95%, , ,
Calculation Example
- Assignment One:
(100 + ((1+1+0)/3)*100)/200
0.833
- Assignment Two:
(81 + ((0+1+0)/3)*100)/200
0.572
- Assignment Three:
(95 + ((0+1+1)/3)*100)/200
0.808
- Overall:
(0.833 + 0.572 + 0.808) / 3 * 100
73.767
Programming Projects¶
- Assignment One:
- Assignment Two:
- Assignment Three:
Calculation Example
- Overall:
(1+0+0)/3 * 100
33.33
Source Code Survey¶
- Assignment One:
- Assignment Two:
- Assignment Three:
Calculation Example
- Overall:
(1+1+1)/3 * 100
100.00
Grade Questions¶
Before asking the instructor a question about the calculation of either your assignment grades or your overall course grade, please make sure that you have already consulted the GitHub repository for each assignment to see your grades and then calculated your grade using the approach outlined in this document. The instructor will use your calculations to support the discussion of any questions that you have about how to calculate either your grade for a project or your overall grade for a computer science course.
Conclusion¶
Unsure about how the instructor will assess your work? Unconvinced that this is a good approach to project assessment? If you have some ideas for improving the assessment strategy please share them in the GitHub Issue Tracker or the GitHub Discussions Forum!
-
Check out the article Finding Common Ground with Grading Systems that Robert Talbert wrote to explain the principles of effective grading. From your perspective as an emerging proactive programmer who wants to grow in their knowledge and skills, what are the best steps for an expert to take when assessing your work? ↩
Ended: Proactive Learning
Data Abstraction ↵
Introduction¶
Quote
"An abstraction is a simplified view of an entity, which omits important details. Abstractions are useful because they make it easier for us to think about and manipulate complex things." John Ousterhout in A Philosophy of Software Design
In the book called A Philosophy of Software Design, John Ousterhout defines an abstraction as "a simplified view of an entity, which omits important details. Abstractions are useful because they make it easier for us to think about and manipulate complex things." Abstraction is a powerful tool that enables software engineers to solve complex problems. The data abstraction course will teach you how to effectively use several different types of abstractions as you solve problems and build software!
Using Python, you will first learn about the programming abstractions (e.g., iteration, recursion, and functions) that are the basic building blocks of computer programs. Second, you will explore the abstractions in object-oriented programming (e.g., inheritance, encapsulation, and polymorphism) that enable software engineers to create and maintain large-scale systems. Using the two previous types of abstractions, you will learn how to create and use abstractions like data structures (e.g., lists and dictionaries) and algorithms (e.g., searching and sorting) as you form the reliable building blocks of complex programs. Finally, you will use performance evaluation abstractions (e.g., worst-case time complexity and doubling experiments) to study the efficiency of all the other data abstractions. Let's learn more about how to confidently create complex software!
Note
This course currently uses the textbook Introduction to Computation and Programming Using Python by John V. Guttag. Even though you must purchase this textbook, all of the supporting materials on this site are available for free. Please stay tuned as future versions of this course will leverage a free and open-access textbook!
Learning Objectives¶
A proactive programmer studying data abstraction should demonstrate the mastery of the following learning objectives in the categories of data structures, rigorous programming, and effective communication. According to Robert Talbert, a learning objective must be "a clear, measurable action that a student should be able to do once the lesson is over".1 For the purposes of this site, these learning objectives are not for a specific lesson but rather an entire course for either an Allegheny College student or, for the duration of self-paced learning, all other emerging proactive programmers.
Data Structures¶
A person learning data abstraction with the mindset of a proactive programmer will be able to demonstrate mastery of the following skills in data structures:
Algorithm Engineering¶
- Correctly implement and/or use a data structure, such as a stack, list, or dictionary, ensuring that it provides all of the functionality required by the program's specification.
- After importing an existing implementation of a data structure (e.g., a list or a dictionary), confirm that it provides the required functionality and integrate it into an existing program.
- Adapt an existing implementation of a data structure so that it offers additional and/or different functionality not provided by that structure's standard implementation.
- Leveraging knowledge of existing data structures like a list or dictionary:
- Specify the input, output, and behavior of functions for a new data structure.
- Design, implement, and document all functions of a new data structure.
- Implement, execute, and maintain a test suite for a new data structure and demonstrate that, for a particular input, its behavior matches the specification.
- Integrate the new data structure with the data structures used by an existing program.
- Document the trade-offs associated with the implementation of the new data structure, comparing and contrasting it with existing alternatives and justifying the need for the bespoke implementation instead of those that are already available.
- Use the principles of object-oriented programming (i.e., encapsulation, inheritance, and polymorphism) to design, implement, document, and test classes that provide all of the features required by the specification of a data structure and the algorithms that process it.
- Use exception handling techniques to ensure that the implementation of a data structure does not inappropriately crash when it runs in non-standard execution circumstances.
- Given input from the file system, network, or console, input the data values, store them in a data structure like a list, and then implement and use a sorting algorithm like merge sort to order the list of values. Using the same list of values, implement and use a search algorithm that can either find a specific value in the list or confirm that the value is not in the list.
- Given input stored in a data structure and solution constraints, use a technique like dynamic programming to solve an optimization problem (e.g., the 0/1 Knapsack Problem).
Algorithm Evaluation¶
- Given the psuedo-code description of an algorithm that processes and/or
manipulates a data structure, perform the following steps as part of its
analytical evaluation:
- Characterize the number of basic operations in both iterative and recursive algorithms.
- Use the asymptotic notation and the characterization of its basic operations to classify an algorithm as belonging to a well-known worst-case time complexity class.
- Using an algorithm's worst-case time complexity, compare and contrast it with other algorithms that have similar and different time complexities, explaining which algorithm is most appropriate depending on, for instance, the likely size of a program's input.
- Describe ways in which it is possible to re-design an algorithm and the way in which it processes a data structure so as to improve its worst-case time complexity.
- Explain how an algorithm exhibits trade-offs between its worst-case time complexity and the amount of space that it needs to store the data structure.
- Given the Python-based implementation of a data structure and the algorithm
that processes and/or manipulates it, perform these steps as part of its
empirical evaluation:
- Implement a benchmarking framework that repeatedly executes an algorithm through a doubling experiment in which the size of the input repeatedly doubles.
- Use the benchmarking framework to run a doubling experiment for an algorithm, computing the doubling ratio for execution time at each stage of a benchmark.
- Use the computed doubling ratio to experimentally predict the likely worst-case time complexity class to which the data structure and algorithm belong.
- Leveraging both the likely worst-case time complexity and the experimental data reported from the doubling experiment run by the benchmarking framework, describe ways in which it is possible to re-design the algorithm to improve its performance.
- Using the likely worst-case time complexity and the experimental data, explain how an algorithm trades-off between time efficiency and the space needed for data storage.
- For the implementation of a data structure and its associated algorithms in
the Python programming language, use the results from both the analytical and
empirical evaluation to:
- Confidently classify the algorithm according to its worst-case time complexity.
- Identify strengths and weakness in terms of both time and space efficiency.
- Suggest ways to improve the efficiency of the Python implementation.
Data Analysis¶
- Given one or more sets of textual, numerical, categorical, and/or combined
data that describe the performance of an algorithm or data structure,
implement, test, use, and evaluate functions that perform data analysis
through these steps:
- Input, process, check, and clean the data sets to confirm their correctness.
- Run an appropriate statistical technique (e.g., the calculation of a mean, median, or standard deviation) to summarize and analyze the performance data.
- Use an appropriate data visualization technique that can create graphs and/or diagrams that highlight the salient properties of the data set (e.g., show the general trends in the data set while drawing attention to the dispersion of the values).
- Use statistical analysis and data visualization techniques to surface trends in a data set.
- Implement and use an appropriate data processing method that transforms the data into any format required by any external functions (e.g., convert from JSON to CSV).
Rigorous Programming¶
A person learning data abstraction with the mindset of a proactive programmer will be able to demonstrate mastery of the following programming skills:
Python Programming¶
- Write short Python functions of ten to twenty lines that have the following
characteristics:
- Has function and variable names that adhere to an industry-standard coding style.
- Has descriptive comments for module definition and both the function's declaration and the function's code that adhere to an industry-standard coding style.
- Features a source code format that adheres to an industry-standard coding style.
- Passes an automated test suite, written with an industry-standard framework such as Pytest, showing that it correctly implements the specification for the function.
- Has an automated test suite, written with an industry-standard framework such as Pytest, that covers at least the 80% of the statements and branches in the function.
- Performs the specified operation in an efficient fashion, as determined through experiments that record the function's performance in seconds or milliseconds.
- Correctly uses assignment statements, iteration constructs, conditional logic, function invocation, and function recursion in a way that passes the function's test suite, works efficiently, and conveys the intended function's purpose in a Pythonic fashion.
- Correctly uses a data structure like a dictionary in a way that passes the test suite, works efficiently, and conveys the intended purpose of the data structure.
- Correctly performs file and console input and output, ensuring that all input and output is displayed and stored correctly, is not corrupted, and is processed efficiently.
- Correctly performs calculations for statistical properties of a data set (e.g., the mean, median, and standard deviation), while also clearly displaying the data, its relevant summarization values, and the interpretation of all statistical properties.
- Write correct Python programs consisting of between one and five hundred lines of source code that correctly solve problems using data structures like a list or dictionary.
- Uses the features of the Python programming language to create classes and instances of these classes that solve problems by using object-oriented programming.
- Implement and run Python programs with the following environments and tools:
- Python programs with dependencies, packaging, and tasks, managed by Poetry.
- Python scripts without external dependencies that are run with the interpreter.
- Jupyter notebooks run through either Jupyter Lite or Google Colab.
- Python code segments run in a read-eval-print loop (REPL) on Jupyter Lite.
Programming Tools¶
- Use a Python programming environment to complete these tasks while
implementing a Python program consisting of between one and five hundred lines
of code:
- Install, upgrade, and use Python 3.8, 3.9, or 3.10 programming environment to create, run, and debug a Python program through a terminal window and/or a text editor.
- Use Poetry to install a Python program's dependencies, create a virtual environment, and run it without error in an isolated and self-contained configuration.
- Use and create a test suite implemented with Pytest to detect a failure in a Python program and then effectively use tools like a text editor and a terminal window to find and fix the fault, ultimately confirming that the Python program no longer contains the fault and that the fix did not compromise other functions in the program.
- Use a text editor like VS Code to implement, test, debug, document, and manage the source code of a Python program, leveraging plugins for workflow enhancement.
Version Control¶
- Use the GitHub platform and the
Git version control system in the following fashion:
- Clone a GitHub repository without error using either a command in a terminal window or an extension for Git integration in a text editor like VS Code.
- Write short and descriptive commit messages that explain the specific way in which a commit changes the source code and documentation in the GitHub repository.
- Navigate reports produced by GitHub Actions so as to determine which aspects of a GitHub repository do and do not adhere to a project's specification.
- Use the GitHub Flow model to implement specific features in a branch of a GitHub repository and then merge that branch to the main one only after all the checks run by GitHub Actions pass as required and code reviews confirm the code's correctness.
- Create and discuss programming and technical writing issues through the use of the GitHub Issue Tracker and the GitHub Discussion Forum, furnishing descriptive titles and problem descriptions that adhere to industry best practices and project templates.
- Submit completed projects that pass all of the instructor-provided and industry-standard checks, as evidenced through the report of a passing build by GitHub Actions.
Effective Learning¶
A person learning data abstraction with the mindset of a proactive programmer will be able to demonstrate mastery of the following technology-mediated communication skills:
-
Follow a systematic process when using resources to implement Python programs:
- After detecting an error in a Python program through the use of tools like GatorGrader or Pytest, develop a satisfactory understanding of the problem's possible root cause and then search sites like Stack Overflow for potential solutions.
- After evaluating suggested solutions to a programming problem that originate from sites like Stack Overflow, develop a way to fix an error in a Python program.
- Independently develop solutions to Python programming problems even if the specific technical challenge that you face was not previously covered in a course session or as part of your prior review of technical content.
-
Use Discord to effectively communicate about technology in the following fashion:
- In the correct public channel, post a question that includes source code segments, screenshots, and a description of the steps taken in an attempt to solve a problem.
- Answer questions that were posted in a public channel, responding with source code segments, screenshots, and links to external references, pointing the proactive programmer who asked the question in the right direction without solving the problem for them and limiting their opportunity to learn more about the topic in question.
- Proactively offer to help others who may need to learn scientific, mathematical, or technical knowledge and skills that a learner has already mastered by sharing the acquired knowledge or skill, how you can be contacted, and how you can best assist.
Improving Objectives¶
As Robert Talbert explains, a learning objective is clear when it is "clear from the students' perspective" and measurable when there is "some way to know whether the objective has been met" or "how far away the learner is from meeting it". Do you see a way in which we can improve the learning objectives for data abstraction? If you do, then please participate in the proactive community by sharing your ideas for improving them!
-
See Robert Talbert's article entitled How to Write Learning Objectives for more details about how to design learning objectives for an academic course. From your perspective what does it mean to write learning objectives that are both clear and measurable? ↩
Course Syllabus¶
Computer Science 101 Fall 2023 (CMPSC 101.00)¶
Course Instructor¶
- Name: Dr. Emily Graber
- Office Location: Alden Hall 106
Instructor Office Hours¶
- Monday: 2:00 PM-3:30 PM, Alden Hall, 15 minute time slots
- TBD
Scheduling Office Hours
To schedule a meeting with the course instructor during office hours, please visit the Google Calendar for Office Hours. You can schedule an appointment by clicking a suitable box in Google Calendar and then reserving an open time slot. At this point, the details about your chosen appointment will appear in both your Google Calendar and the instructor's Google Calendar. Please arrive five minutes in advance for your meeting and be aware that, by necessity, the meeting before yours may sometimes run late.
Course Meeting Schedule¶
- Discussion and Group Work Session: Monday and Wednesday, 10 AM-10:50 AM, Alden 109
- Programming Session: Friday, 10 AM-10:50 AM, Alden 109
- Laboratory Session: Friday, 2:30 PM-4:20 PM, Alden 109
Course Description¶
A continuation of CMPSC 100 with an emphasis on implementing, using, and evaluating the computational structures needed to efficiently store and retrieve digital data. Participating in hands-on activities that often require teamwork, students create data structures and algorithms whose correctness and performance they study through proofs and experimentation. Students continue to refine their ability to organize and document a program's source code so that it effectively communicates with the intended users and maintainers. During a weekly laboratory session, students use state-of-the-art technology to complete projects, reporting on their results through both written documents and oral presentations.
- Prerequisite: CMPSC 100 or permission of the instructor.
- Distribution Requirements: QR, SP.
What do these distribution requirements mean?
Quantitative Reasoning (QR): Quantitative Reasoning is the ability to understand, investigate, communicate, and contextualize numerical, symbolic, and graphical information towards the exploration of natural, physical, behavioral, or social phenomena.
Learning Outcome: Students who successfully complete this requirement will demonstrate an understanding of how to interpret numeric data and/or their graphical or symbolic representations.
Scientific Process and Knowledge (SP): Courses involving Scientific Process and Knowledge aim to convey an understanding of what is known or can be known about the natural world; apply scientific reasoning towards the analysis and synthesis of scientific information; and create scientifically literate citizens who can engage productively in problem solving.
Learning Outcome: Students who successfully complete this requirement will demonstrate an understanding of the nature, approaches, and domain of scientific inquiry.
Required Textbook¶
Introduction to Computation and Programming Using Python by John V. Guttag
To order through the virtual campus bookstore, click on the "Let's get started" button, and enter Fall 2023, Computer Science, CMPSC 101.
Course Schedule¶
- Week One: August 29 to September 1: Software Operation
- Week Two: September 4 to September 8: Python Foundations
- Week Three: September 11 to September 15: Numerical Computation
- Week Four: September 18 to September 22: Function Scope
- Week Five: September 25 to September 29: Proactive Review
- Executable Examination One: September 29 during the laboratory session
- Relevant Modules:
- Week Six: October 2 to October 6: Structured Types
- Monday October 9: Fall Break
- Week Seven: October 11 to October 13: Program Components
- Week Eight: October 16 to October 20: Software Testing
- Week Nine: October 23 to October 27: Object-Oriented Programming
- Week Ten: October 30 to November 3: Proactive Review
- Executable Examination Two: November 3 during the laboratory session
- Relevant Modules:
- Week Eleven: November 6 to November 10: Algorithmic Complexity
- Week Twelve: November 13 to November 17: Algorithmic Complexity
- Week Thirteen: November 20 to November 24: Thanksgiving Break
- Week Fourteen: November 27 to December 1: Data Structures
- Week Fifteen: December 4 to December 8: Optimization Problems
- Week Sixteen: December 11: Proactive Review
- Final Examination: Examination Code: G, Date: Monday, December 18th, 2023 at 09:00 AM. Complete Final Exam Schedule
- Comprehensively covers all course modules
Course Policies¶
Grading¶
The grade that a student receives in this class will be based on the following categories. All of these percentages are approximate and, if the need to do so presents itself, the course instructor may change the assigned percentages during the academic semester.
Category | Percentage |
---|---|
Course Participation | 5% |
Midterm Examinations | 10% |
Final Examination | 15% |
Source Code Surveys | 15% |
Programming Projects | 15% |
Engineering Efforts | 40% |
These grading categories have the following definitions:
-
Course Participation: Students are expected to regularly attend and actively participate in all class and laboratory sessions. After either an unexcused absence or a late attendance to a either a class or laboratory session on two separate occasions, a student's course participation grade will be reduced by half a percentage for each additional time they are absent or late in an unexcused fashion. Students who need to miss class or attend class late for an excused reason should communicate their situation to the course instructor as soon as possible. The content that a student commits to their GitHub repositories during the weeks devoted to proactive review are also a component of a student's grade for class participation.
-
Midterm Examinations: The midterms are online cumulative assessments covering all prior material from the class, programming, and laboratory sessions, as outlined on the course schedule. Unless prior arrangements are made with the instructor, all students should use their computer to take this test on the scheduled date and to complete it in the stated location while taking no more than the required amount of time. Each midterm is an executable examination that a student will complete through the use of GitHub, VS Code, and the programming tools installed on their laptops.
-
Final Examination: The final is an online cumulative assessment covering all of the material from the class, programming, and laboratory sessions, as outlined on the course schedule. Unless prior arrangements are made with the instructor, all students should use their computer to take this test on the scheduled date and to complete it in the stated location while taking no more than the required amount of time. The cumulative final is an executable examination that a student will complete through the use of GitHub, VS Code, and the programming tools installed on their laptops.
-
Source Code Surveys: Graded on a checkmark basis and building on material in the textbook and the content covered during that week's in-person classroom sessions, source code surveys have the following goals: (i) help a learner to demonstrate that they can remember learned material by recalling facts, basic concepts, and answers to questions presented in the textbook and on the course web site and (ii) allow a learner to demonstrate an understanding of facts and ideas by translating, interpreting, and stating the main technical ideas presented through the textbook and course web site.
-
Programming Projects: Graded on a checkmark basis and building on material available in the textbook and the content covered during that week's in-person classroom session, the programming projects further equip a learner to solve new problems in the field of data abstraction by applying — in a new way — their knowledge of the facts and techniques of data abstraction and rigorous Python programming.
-
Engineering Efforts: These assignments invite students to explore different techniques for rigorously designing, implementing, evaluating, and documenting real-world Python programs. These assignments also encourage students to use tools like a text editor, a terminal window, and a modern Python development environment to implement functions that strike the right balance between understandability, generalizability, and specialization. Students will also use the data collected from running experiments to evaluate the implementation of a Python function as they consider trade-offs between, for instance, its efficiency, flexibility, and correctness.
Assignment Submission¶
All assignments will have a stated due date shared through GitHub, GitHub Classroom, and Google Calendar. Electronic versions of the engineering efforts, programming projects, and source code surveys must be submitted to the instructor through a student's GitHub repository created by GitHub Classroom. No credit will be awarded for any course work that you submit to the incorrect GitHub repository. Unless special arrangements are made with the instructor, no work will be accepted after the published assignment deadline.
Assignment Evaluation¶
Using a report that the instructor shares with you through your assignment's GitHub repository, you will privately receive a grade for and feedback on each assignment. Your grade will be a function of whether or not you completed correct work that fulfills the project's specification and submitted it by the deadline. Please refer to the description of proactive learning for more details about the evaluation of course assignments.
Course Attendance¶
It is mandatory for all students to attend the course sessions. If, due to extenuating circumstances, you will not be able to attend a session, then, whenever possible, please communicate with the instructor at least one week in advance to describe your situation. Students who have any signs of illness should not attend any in-person course sessions.
Class Preparation¶
In order to minimize confusion and maximize learning, students must invest time to prepare for the class discussions, laboratory, and programming sessions. During the class periods, the course instructor will often pose challenging questions that could require group discussion, the creation of a Python program or data table, a vote on a thought-provoking issue, or an in-class presentation. Only those students who have prepared for class by reading the assigned material and reviewing the current reading assignments course projects will be able to effectively participate in these class discussions.
Importantly, only prepared students will be able to acquire the knowledge and skills that they need to be successful in this course, subsequent courses, and the field of web development. In order to help students remain organized and to effectively prepare for classes, the course instructor will maintain a class schedule with reading assignments and presentation slides, available on this site. During the class sessions students will also be required to download, use, and modify Python software components and data sets that are made available through means such as the course web site or a GitHub repository.
Seeking Assistance¶
Students who are struggling to understand the knowledge and skills developed in either a class, laboratory, or programming session are encouraged to seek assistance from the course instructor and the student technical leaders. Students should, within the bounds of the Honor Code, ask and answer questions on the Discord server for our course; please request assistance from the instructor and student technical leaders first through Discord before sending an email. Students who need the course instructor's assistance must schedule a meeting through the instructor's office hours calendar and come to the meeting with all of the details needed to discuss their question. Students can find out the office hour schedule for student technical leaders by viewing the list of student technical leaders.
Using GitHub and Discord¶
This course will primarily use GitHub and Discord for all course communication, as summarized in the list of community connections. We will use GitHub for the sharing of both source code and course projects and for reporting issues in those materials. We will use two distinct Discord servers for all course discussions. The Proactive Programmers Discord Server provides a way for members of the proactive community to use text and video to chat with each other and will be the main forum for discussing technical content in data abstraction. The Allegheny College Computer Science Discord Server will be the main forum for Department of Computer Science announcements.
Using Email¶
Although we will primarily use Discord for class communication, the course instructor will sometimes use email to send announcements about important matters such as changes in the schedule. It is your responsibility to check your email at least once a day and to ensure that you can reliably send and receive emails. This class policy is based on the statement about the use of email that appears in The Compass, the College's student handbook; please see the instructor if you do not have this handbook.
Honor Code¶
The Academic Honor Program that governs the entire academic program at Allegheny College is described in the Allegheny Academic Bulletin. The Honor Program applies to all work that is submitted for academic credit or to meet non-credit requirements for graduation at Allegheny College. This includes all work assigned for this class (e.g., examinations and course assignments). All students who have enrolled in the College will work under the Honor Program. Each student who has matriculated at the College has acknowledged the following Honor Code pledge:
I hereby recognize and pledge to fulfill my responsibilities, as defined in the Honor Code, and to maintain the integrity of both myself and the College community as a whole.
Effective Collaboration¶
Computer science is an inherently collaborative discipline. People must work together to produce large, complex, and ultimately useful software systems. Because of this, the Department of Computer Science at Allegheny College encourages students to engage in collaboration. However, in the context of individual coursework, through which each student must demonstrate their own knowledge, there are certain forms of collaboration that are and are not acceptable.
-
Acceptable forms of collaboration include:
- Discussing high-level concepts, such as the use cases for
while
loops or the various methods that can add elements to alist
. - Referring someone to a course text book, course slides, example programs, or other resources that contain helpful information or instructions.
- Outlining the high-level steps to solving a problem or implementing a feature, without mentioning specific lines of code that need to be written.
- Discussing high-level concepts, such as the use cases for
-
Unacceptable forms of collaboration include:
- Sharing details about specific lines of code, including showing your source code to someone or looking at someone else's code.
- Copying someone else's source code, technical writing, program commands, or program output, even with some slight modifications.
- Typing source code, technical writing, or commands on someone else’s computer.
The aforementioned forms of communication are unacceptable because they make it difficult for both the course instructor and a learner to assess individual knowledge. Moreover, these unacceptable forms of collaboration can impede your learning or someone else's learning since an individual is less likely to understand source code or technical writing that they do not create by themself. Any student who participates in these unacceptable forms of collaboration, whether they are the one sharing, showing, looking, copying, or typing, are in violation of Allegheny College's Honor Code.
In summary, students should collaborate as long as they do so in acceptable ways. If a student needs assistance beyond what can be gained through acceptable forms of collaboration, they should seek help from the course instructor or a technical leader. If a student submits deliverables (e.g., source code or technical writing) that are nearly identical to the work of others, this will be taken as evidence of violating the Honor Code.
Disability Services¶
The Americans with Disabilities Act (ADA) is a federal anti-discrimination statute that provides comprehensive civil rights protection for persons with disabilities. Among other things, this legislation requires all students with disabilities be guaranteed a learning environment that provides for reasonable accommodation of their disabilities. Students with disabilities who believe they may need accommodations in this class are encouraged to contact Disability Services at 814-332-2898. Disability Services is part of the Learning Commons and is located in Pelletier Library. Please do this as soon as possible to ensure that approved accommodations are implemented in a timely fashion.
Welcome Message¶
In reference to software, Frederick P. Brooks, Jr. wrote in chapter one of The Mythical Man Month that "the magic of myth and legend has come true in our time." It is so exciting that we can write programs that "come alive" on our computers! Moreover, efficient Python programs that correctly use, store and manipulate data have the potential to positively influence the lives of many people. Moreover, the design, implementation, evaluation, and documentation of Python-based software are exciting and rewarding activities! The course instructor invites you to proactively pursue, with great enthusiasm and vigor, this adventure in data abstraction and rigorous Python programming.
Note
This syllabus is for learners who enrolled in a for-credit Computer Science class at Allegheny College. Even though external learners are not bound by the rules in this syllabus, they can rely on the team of programming experts and the members of the proactive community to complete the projects on this web site.
Course Schedule¶
Software Operation¶
Technical Question¶
- How do I install and use the industry-standard programming tools that will help me to rigorously explore data abstraction with the Python programming language?
Next Steps¶
- All written content in and tutorials referenced by the list of proactive technical skills.
Python Foundations¶
Technical Question¶
- How can I use functions, variables, conditional logic, and iteration constructs, as provided by Python, to implement programs that, for instance, find out if a number is even or odd, compute a number's square, or determine if a number is divisible by another number?
Next Steps¶
- Read chapters 1 and 2 of Introduction to Computation and Programming Using Python
- Check out the course slides for a detailed investigation of these chapters!
- Run the Jupyter notebooks in
data-abstraction/python-foundations/
with: - Check out this Engineering Effort on Integer Squaring
Technical Concepts
- Syntax: the structure of a programming language that defines what characters and symbols are well formed
- Semantics: the way in which a programming language associates meaning with syntactically correct programs
- Notional Machine: idealized abstraction of both computer hardware and the semantics of a computer program
- Reserved Word: a keyword in Python that has a built-in meaning and cannot be used for a variable's name
- Type Checking: automated process to confirm the compatibility of the types for both variables and operations
Numerical Computation¶
Technical Question¶
- How can I use functions, floating-point variables, conditional logic, and iteration constructs to implement both exhaustive and approximate approaches to compute (i) the square root of a number, (ii) the logarithm of a number, and (iii) the roots of a polynomial function?
Next Steps¶
- Read chapter 3 of Introduction to Computation and Programming Using Python
- Check out the course slides for a detailed investigation of these chapters!
- Run the Jupyter notebooks in
data-abstraction/numerical-computation/
with: - Check out this Engineering Effort on Primality Testing
- Check out this Source Code Survey on Numerical Data
Technical Concepts
- Numerical Approximation: an alternative to the exact value for a function that is close enough to be useful
- Floating Point: representing a decimal value with two integers, one for significant digits and one for exponent
- Binary Number: representation of a number using only a sequence of bits, or digits that must only be 0 or 1
- Quadratic Root: value(s) of a quadratic function where it intercepts the horizontal axis
- Square Root: mathematical function that is the inverse of the square of a number
Function Scope¶
Technical Question¶
- How can I use Python's scoping rules and the principle of abstraction to create modularized and/or higher-order functions that are easy to understand, implement, test, and maintain?
Next Steps¶
- Read chapter 4 of Introduction to Computation and Programming Using Python
- Check out the course slides for a detailed investigation of these chapters!
- Run the Jupyter notebooks in
data-abstraction/function-scope/
with: - Check out this Programming Project on Number Comparison
- Check out this Programming Project on Square Roots
Technical Concepts
- Function Specification: the assumptions and guarantees in the contract between function creator and caller
- Formal Parameters: a function's input parameter, given a name and a type in the function's declaration
- Actual Parameters: the arguments to a function that are passed into it at the function invocation point
- Debugging: the systematic process of finding out why a program does not work and then fixing it
- Higher-Order Function: general-purpose functions for problem solving that accept functions as input
Structured Types¶
Technical Question¶
- How can I use Python's structured types (e.g.,
str
,list
,range
, anddict
) to implement programs that efficiently store and retrieve data?
Next Steps¶
- Read chapter 5 of Introduction to Computation and Programming Using Python
- Check out the course slides for a detailed investigation of these chapters!
- Run the Jupyter notebooks in
data-abstraction/structured-types/
with: - Check out this Engineering Effort on Fibonacci Algorithms
Technical Concepts
- Tuple: immutable ordered sequence that can contain elements of any type
- List: ordered sequence of values where each value is identified by an index
- Set: unordered collection of unique elements used for data storage
- Dictionary: container structure like a list, except for the fact that it is indexed with a key
- Shallow Copy: creation of a new list that involves inserting contained objects into a new list
Program Components¶
Technical Question¶
- How can I use different types of program components, such as recursive functions, modules, libraries, and files to implement efficient programs with effective designs?
Next Steps¶
- Read chapters 6 and 7 of Introduction to Computation and Programming Using Python
- Check out the course slides for a detailed investigation of these chapters!
- Run the Jupyter notebooks in
data-abstraction/program-components/
with: - Check out this Engineering Effort on Intersection Algorithms
Technical Concepts
- Recursive Function: function that repeatedly calls itself until reaching a base case that stops recursion
- Global Variable: a variable that is accessible to all of the functions in a module
- Module: a Python file that contains definitions of variables and functions accessible to a program
- Standard Library: collection of packages available to all Python programs through an import statement
- File: disk-based storage mechanism that contains content created by humans and/or computer programs
Software Testing¶
Technical Question¶
- How can I use the processes of software testing and debugging to establish a confidence in the correctness of a Python program?
Next Steps¶
- Read chapter 8 of Introduction to Computation and Programming Using Python
- Check out the course slides for a detailed investigation of these chapters!
- Run the Jupyter notebooks in
data-abstraction/software-testing/
with: - Check out this Engineering Effort on Palindrome Checking
- Check out this Source Code Survey on Debugging Functions
Technical Concepts
- Testing: process of running a program to try to ascertain whether or not it works as intended
- Debugging: process of trying to fix a program that does not currently work as intended
- Unit Testing: writing and running test cases designed to ensure that small units of functionality work correctly
- Regression Testing: process of re-running test cases whenever a programmer makes any program changes
- Defensive Programming: creating software to ensure that defects are overt and persistent
Object-Oriented Programming¶
Technical Question¶
- How can I use the principles and primitives of object-oriented programming to implement Python programs with top-notch and easy-to-understand designs?
Next Steps¶
- Read chapters 9 and 10 of Introduction to Computation and Programming Using Python
- Check out the course slides for a detailed investigation of these chapters!
- Run the Jupyter notebooks in
data-abstraction/object-oriented/
with: - Check out this Engineering Effort on Object Processing
- Check out this Source Code Survey on Structured Types
Technical Concepts
- Exception: something that does not conform to the normal expectation for program behavior
- Unhandled Exception: an exception that is raised that causes the program to stop running
- Try-Except Block: key building block for exception handling in the Python pogramming language
- Inheritance: mechanism for building groups of related abstractions that establishes a parent-child relationship
- Information Hiding: the client of a class should only rely on the public methods of the class
Algorithmic Complexity¶
Technical Question¶
- How can I implement more efficient Python programs by conducting both an analytical and an empirical evaluation of the performance of an algorithm?
Next Steps¶
- Read chapter 11 of Introduction to Computation and Programming Using Python
- Check out the course slides for a detailed investigation of these chapters!
- Run the Jupyter notebooks in
data-abstraction/algorithmic-complexity/
with: - Check out this Engineering Effort on Sorting Algorithms
Technical Concepts
- Random Access Machine: model of computation in which steps are executed sequentially one at a time
- Best-Case Running Time: minimum running time over all possible inputs of a given size
- Worst-Case Running Time: maximum running time over all possible inputs of a given size
- Average-Case Running Time: average (or, expected) running time over all possible inputs of a given size
- Asymptotic Notation: relationship between the running time of an algorithm and the size of its inputs
Data Structures¶
Technical Question¶
- How can I implement, use, and test data structures that support efficient data processing with searching and sorting algorithms?
Next Steps¶
- Read chapter 12 of Introduction to Computation and Programming Using Python
- Check out the course slides for a detailed
- Run the Jupyter notebooks in
data-abstraction/algorithmic-complexity/
with: - Check out this Source Code Survey on Container Cloning
- Check out this Engineering Effort on Containment Checking
Technical Concepts
- Search Algorithm: method for finding an item or a group of items in a collection of items
- Search Space: the collection of items subject to search
- Indirection: accessing something by first accessing something else that contains a reference to it
- Merge Sort: sorting algorithm that employs divide-and-conquer approach to sorting data
- Stable Sorting: process of sorting data such that the order of equal items in an input list are preserved
Optimization Problems¶
Technical Question¶
- How can I use algorithms to efficiently solve an optimization problem (e.g., the 0/1 knapsack problem) characterized by an objective function and a set of constraints?
Next Steps¶
- Read chapters 14 and 15 of Introduction to Computation and Programming Using Python
- Check out the course slides for a detailed investigation of these chapters!
- Run the Jupyter notebooks in
data-abstraction/optimization-problems/
with: - Check out this Programming Project on Matrix Processing
- Check out this Source Code Survey on Optimization
Technical Concepts
- Objective Function: a function that is to either be maximized or minimized in order to achieve a goal
- Optimization Constraints: restrictions on the solution to an optimization problem
- Knapsack Problem: optimization problem with the goal of maximizing a benefit and minimizing a weight
- Greedy Algorithm: practical approach to solving optimization problems that chooses the next best item
- Dynamic Programming: strategy for problems that exhibit overlapping subproblems and optimal substructure
Learning Opportunities¶
Interested in learning more about any of the topics on this schedule? If you are, then make sure to connect with members of the proactive community for more learning opportunities. Remember, this course emphasizes building mastery of the course's learning objectives through "learning by doing", as explained in the description of proactive learning. As such, you can best understand the content on this schedule by completing all the source code surveys, programming projects, and engineering efforts!
Source Code Surveys ↵
Numerical Data¶
Project Goals¶
This assignment invites you to run and observe two Python programs called
determine-even-odd
and floating-point-confusion
. Instead of using the
Poetry tool for managing dependencies and
packaging these programs, which the technical
skills advise as a best
practice, these programs are scripts, without any dependencies on other Python
packages, that you can run through the Python interpreter. As you learn a new
way to run a Python program and use tools like VS Code and a terminal window,
this project offers you the opportunity to ensure that you understand how to (i)
use the modular arithmetic operation (i.e., %
) to determine if a number is
even or odd and (ii) correctly multiply and add with float-point variables.
Ready for some programming fun? Okay, let's get started!
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to add source code and documentation to the
project so that you can refine your understanding of how to process numerical
data in Python!
Note
If you are an emerging proactive programmer who is not enrolled in a Computer Science class at Allegheny College, you can still work on this assignment! To get started, you should click the "Use this template" button in the numerical-data-starter GitHub repository and create your own version of this project's source code. After creating your GitHub repository, you can follow all of the other steps!
Code Survey¶
If you change into the source/
directory of your GitHub repository, you will
see two Python files called determine-even-odd.py
and
floating-point-confusion.py
. You can run the determine-even-odd.py
program
by typing python determine-even-odd.py
in your terminal window. What output
does the program produce? Can you explain why it produces this output? The key
to understanding this segment of source code is to notice that line 1
uses the
modular arithmetic operation, written as %
, to compute the remainder that
results from dividing the variable called value
by 2
. If 2
divides value
evenly, then the remainder will be 0
and this code segment concludes that the
number is even. However, if the remainder resulting from dividing value
by 2
is not equal to 0
, then there is clear evidence that value
is odd.
1 2 3 4 |
|
The second program is called floating-point-confusion.py
because it
illustrates some of the initially confusing aspects of using Python's float
data type to store decimal values. To understand this program better, it is
important to note that lines 1
and 2
in the following segment illustrate the
respective use of addition and multiplication with float-point numbers. You can
run this program by typing python floating-point-confusion.py
in your
terminal. Can you explain why it produces this output and what it reveals about
the challenges of doing arithmetic with float-point numbers?
1 2 3 |
|
Note
Don't forget that if you want to run one of the provided Python scripts
program you must use your terminal window to first go into the GitHub
repository containing this project and then go into the source/
directory
that contains the project's source code. You should also use VS Code to
study the provided source code to ensure that you understand why it produces
the output that you see in your terminal window.
Running Checks¶
Since this project does not use Poetry to manage
project dependencies and virtual environments, it does not support the use of
commands like poetry run task test
. However, you can leverage the relevant
instructions in the technical
skills to run the command
gatorgrade --config config/gatorgrade.yml
to check your work. If your work
meets the baseline requirements and adheres to the best practices that proactive
programmers adopt you will see that all the checks pass when you run
gatorgrade
. You can study the config/gatorgrade.yml
file in your repository
to learn how
GatorGrade runs
GatorGrader to automatically
check your program and technical writing.
Note
Did you know that GatorGrade and GatorGrader are open-source Python programs implemented by many proactive programmers? If you finish this source code survey and have extra time, please brainstorm some new features that you think these two tools should have, explain your idea by raising an issue in the relevant project's GitHub repository, and take the first step towards implementing and testing your idea. If the maintainers of these tools accept your new feature then you will have helped to improve the experience of other people who use GatorGrade and GatorGrader!
Project Reflection¶
Once you have finished all of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file. Since
this is a source code survey, you should provide output from running each of the
provided Python programs on your own laptop and then explain how the program's
source code produced that output. A specific goal for this project is to ensure
that you can explain how Python programs should correctly use modular arithmetic
and floating point numbers to achieve a practical goal.
Project Assessment¶
Since this project is source code survey, it is aligned with the remembering and understanding levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet the project's specification.
Note
Before you finish all of the required deliverables required by this project is worth pausing to remember that the instructor will give advance feedback to any learner at Allegheny College who requests it through GitHub and Discord at least 24 hours before the project's due date! Seriously, did you catch that? This policy means that you can thoroughly understand the ways to improve your project before its final assessment! To learn more about this opportunity, please read the assessment strategy for this site.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.
Structured Types¶
Project Goals¶
This assignment invites you to run and observe two Python programs called
compute-tuple-intersection
and perform-apply-to-each
. Instead of using the
Poetry tool for managing dependencies and
packaging these programs, which the technical
skills advise as a best
practice, these programs are scripts, without any dependencies on other Python
packages, that you can run through the Python interpreter. As you continue to
practice a different way to run a Python program, this project offers you the
opportunity to improve your understanding of how to compute the intersection (or
elements in common) between two tuples that can contain an arbitrary number of
values each of an arbitrary type. You will also learn more about high-order
functions as you implement a program that can apply an arbitrary function to the
contents of an arbitrary length list of int
values.
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to add source code and documentation to the
project, enabling you to understand more about tuples and higher-order
functions.
Note
If you are an emerging proactive programmer who is not enrolled in a Computer Science class at Allegheny College, you can still work on this assignment! To get started, you should click the "Use this template" button in the structured-types-starter GitHub repository and create your own version of this project's source code. After creating your GitHub repository, you can follow all of the other steps!
Code Survey¶
If you change into the source/
directory of your GitHub repository, you will
see two Python files called compute-tuple-intersection.py
and
perform-apply-to-each.py
. You can run the compute-tuple-intersection.py
program by typing python compute-tuple-intersection.py
in your terminal
window. This program currently has several TODO
markers asking you to add
source code from the text book to provide an implementation of a function with
the following signature: def compute_intersection(tuple_one: Tuple[Any, ...],
tuple_two: Tuple[Any, ...]) -> Tuple[Any, ...]
. Once you have added the
required source code your program should produce the following output. Can you
explain why different calls to compute_intersection
yield output with the
same elements but in a different order?
The first tuple: (1, 'a', 2)
The second tuple: ('b', 2, 'a')
The first intersection tuple: ('a', 2)
The second intersection tuple: (2, 'a')
The second program in the source/
directory is called perform-apply-to-each
.
Again, this program has several TODO
markers that invite you to add source
code from the text book to finish the implementation of the function with the
signature def apply_to_each(values: List[int], function: Callable) -> None
.
After you have added the required source code your program should produce the
following output. One interesting aspect of the apply_to_each
function is that
it does not return any values, as indicated by the return type annotation of
None
. If the function does not return a value, then how can it modify the
values
input parameter of type List[int]
as shown in the output? Finally,
you will note that apply_to_each
accepts a function
parameter of type
Callable
, making it a higher-order function. What are the benefits of using
high-order functions in Python programs? How does apply_to_each
use the
function
parameter?
Values before transformations: [1, -2, 3.33]
Values after applying abs: [1, 2, 3.33]
Values after applying int: [1, 2, 3]
Values after applying squaring: [1, 4, 9]
Running Checks¶
Since this project does not use Poetry to manage
project dependencies and virtual environments, it does not support the use of
commands like poetry run task test
. However, you can leverage the relevant
instructions in the technical
skills to run the command
gatorgrade --config config/gatorgrade.yml
to check your work. If your work
meets the baseline requirements and adheres to the best practices that proactive
programmers adopt you will see that all the checks pass when you run
gatorgrade
. You can study the config/gatorgrade.yml
file in your repository
to learn how
GatorGrade runs
GatorGrader to automatically
check your program and technical writing.
Note
Did you know that GatorGrade and GatorGrader are open-source Python programs implemented by many proactive programmers? If you finish this source code survey and have extra time, please brainstorm some new features that you think these two tools should have, explain your idea by raising an issue in the relevant project's GitHub repository, and take the first step towards implementing and testing your idea. If the maintainers of these tools accept your new feature then you will have helped to improve the experience of other people who use GatorGrade and GatorGrader!
Project Reflection¶
Once you have finished all of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file. Since
this is a source code survey, you should provide output from running each of the
provided Python programs on your own laptop and then explain how the program's
source code produced that output. A specific goal for this project is to ensure
that you can explain each component of a function's type signature, including
details about its inputs and outputs.
Project Assessment¶
Since this project is source code survey, it is aligned with the remembering and understanding levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet the project's specification.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.
Debugging Functions¶
Project Goals¶
This assignment invites you to run and observe two Python programs called
perform-primality-check
and perform-abs-computation
. Instead of using the
Poetry tool for managing dependencies and
packaging these programs, which the technical
skills advise as a best
practice, these programs are scripts, without any dependencies on other Python
packages, that you can run through the Python interpreter. As you continue to
practice a different way to run a Python program, this project offers you the
opportunity to improve your understanding of how to debug and test Python
functions that have a defect inside of them. Specifically, you will write test
cases that (i) create an input for a function, (ii) pass that input to the
function under test, (iii) capture the output of the function under test, and
(iv) assert that the captured function output equals the expected output if the
function was implemented correctly. Instead of using a test automation framework
to run these tests you will organize them into functions in the same module as
the function under test.
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to ensure that you understand the debugging
process for Python programs by practicing the skill in a hands-on fashion.
Note
If you are an emerging proactive programmer who is not enrolled in a Computer Science class at Allegheny College, you can still work on this assignment! To get started, you should click the "Use this template" button in the debugging-functions-starter GitHub repository and create your own version of this project's source code. After creating your GitHub repository, you can follow all of the other steps!
Code Survey¶
If you change into the source/
directory of your GitHub repository, you will
see two Python files called perform-primality-check.py
and
perform-abs-computation.py
. The perform-primality-check
module contains a
defective function with the signature def is_prime(x: int) -> bool
. Your task
is to identify and fix the defects inside of this function! To aid your
debugging efforts, you should use and extend the def test_is_prime() -> None
function that should subject the is_prime
function to several tests. The first
test in the test_is_prime
is implemented in the following fashion:
1 2 3 4 5 6 7 8 9 |
|
In the first part of this function, line 3
indicates that the test will input
the value of 0
to the is_prime
function and line 4
shows that the expected
output of is_prime
for this input is False
because 0
is not a prime
number. Line 5
of this function calls the is_prime
function with the
previously constructed input and then lines 6
through 9
provide some
diagnostic output that explains whether or not the output was correct.
Specifically, if the actual output from the function is not equal to the
expected output, then line 7
displays a message indicating that the output is
not correct. When the expected output is equal to is_prime
's actual output,
then line 9
displays a message revealing that the function works correctly.
Even though this test does not use a specific test automation framework it
illustrates the key steps that a test case should take to both find defects and
establish a confidence in the correctness of is_prime
.
After adding more test cases to the perform-primality-check
module, you should
follow the same process when you debug and test the abs
function in the
perform-abs-computation
module. Ultimately, you should ensure that both of the
defective functions no longer have defects inside of them! For instance, when
the test cases for the is_prime
function are passing correctly they should
produce the following output:
Expected output correct for input of zero!
Expected output correct for input of one!
Expected output correct for input of two!
Expected output correct for input of forty-one!
Running Checks¶
Since this project does not use Poetry to manage
project dependencies and virtual environments, it does not support the use of
commands like poetry run task test
. However, you can leverage the relevant
instructions in the technical
skills to run the command
gatorgrade --config config/gatorgrade.yml
to check your work. If your work
meets the baseline requirements and adheres to the best practices that proactive
programmers adopt you will see that all the checks pass when you run
gatorgrade
. You can study the config/gatorgrade.yml
file in your repository
to learn how
GatorGrade runs
GatorGrader to automatically
check your program and technical writing.
Note
Did you know that GatorGrade and GatorGrader are open-source Python programs implemented by many proactive programmers? If you finish this source code survey and have extra time, please brainstorm some new features that you think these two tools should have, explain your idea by raising an issue in the relevant project's GitHub repository, and take the first step towards implementing and testing your idea. If the maintainers of these tools accept your new feature then you will have helped to improve the experience of other people who use GatorGrade and GatorGrader!
Project Reflection¶
Once you have finished all of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file. Since
this is a source code survey, you should provide output from running each of the
provided Python programs on your own laptop and then explain how the program's
source code produced that output. A specific goal for this project is to ensure
that you can explain each defect that you found in the function and how the test
cases that you implemented helped you to find it. You should also reflect on how
the tests that you created as part of this source code survey are similar to and
different from the ones you might create with a framework like
Pytest. Finally, make sure that you take time to
think through the strategy you have adopted for debugging Python functions,
further considering the ways in which you can improve it.
Project Assessment¶
Since this project is source code survey, it is aligned with the remembering and understanding levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet the project's specification.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.
Container Cloning¶
Project Goals¶
This assignment invites you to study, repair, and test a Python programs called
perform-container-cloning
. Specifically, it affords you to opportunity to
continue to practice the task of debugging and testing a Python function that
has defects inside of it. After learning more about how containers are cloned in
a Python program and why this is needed when a program iterates through a
collection while changing it at the same time, you will find a fix the fault in
the provided source code. Once you have fixed the defect, you will document a
provided test case that (i) creates an input for a function, (ii) passes that
input to the function under test, (iii) captures the output of the function
under test, and (iv) asserts that the captured function output equals the
expected output if the function was implemented correctly. Instead of using a
test automation framework to run the provided test you will run a function to
complete the aforementioned steps.
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to add source code and documentation to the
project so that you can learn more about how to clone a container in Python!
Note
If you are an emerging proactive programmer who is not enrolled in a Computer Science class at Allegheny College, you can still work on this assignment! To get started, you should click the "Use this template" button in the debugging-functions-starter GitHub repository and create your own version of this project's source code. After creating your GitHub repository, you can follow all of the other steps!
Code Survey¶
If you change into the source/
directory of your GitHub repository, you will
see one Python file called perform-container-cloning.py
. The
perform-container-cloning
module contains a defective function with the
signature def remove_duplicates(list_one: List[Any], list_two: List[Any]) ->
Tuple[List[Any], List[Any]]
. Your task is to identify and fix the defects
inside of this function! To aid your debugging efforts, you should use and
extend the def test_remove_duplicates() -> bool
function that should subject
the remove_duplicates
function to several tests. Although it does not use
Pytest, it is possible to implement a test called test_remove_duplicates
in
the following fashion:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Lines 1
and 2
of this function create two lists, called list_one
and
list_two
, that have in common the values 1
and 2
. Lines 3
and 4
of
this function indicate that, if the remove_duplicates
function worked
correctly, then its output should be a tuple container the lists [3, 4]
and
[5, 6]
. After making the assumption that the test case will pass on line 5
,
the function calls remove_duplicates
and checks to see if the expected output
equals the actual output returned by the function. If the expected output is
correct, then line 8
displays a message indicating that is the case.
Otherwise, lines 10
through 13
signal that the test did not pass and display
diagnostic output to highlight this fact for the tester. Ultimately, if this
test case passes correctly it will help to establish a confidence in the
correctness of remove_duplicates
. When the test case for the
remove_duplicates
function passes, then it should produce the following
output:
Expected output correct for input lists: [1, 2, 3, 4] and [1, 2, 5, 6]
The test case passed!
Running Checks¶
Since this project does not use Poetry to manage
project dependencies and virtual environments, it does not support the use of
commands like poetry run task test
. However, you can leverage the relevant
instructions in the technical
skills to enter into a Docker
container and run the command gradle grade
to check your work. If gradle
grade
shows that all checks pass, you will know that you made progress towards
correctly implementing and writing about this project's program.
Note
Did you know that GatorGrade and GatorGrader are open-source Python programs implemented by many proactive programmers? If you finish this source code survey and have extra time, please brainstorm some new features that you think these two tools should have, explain your idea by raising an issue in the relevant project's GitHub repository, and take the first step towards implementing and testing your idea. If the maintainers of these tools accept your new feature then you will have helped to improve the experience of other people who use GatorGrade and GatorGrader!
Project Reflection¶
Once you have finished all of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file.
Since this is a source code survey, you should provide output from running each
of the provided Python programs on your own laptop and then explain how the
program's source code produced that output. A specific goal for this project is
to ensure that you can explain the syntax and meaning of function signatures
like def remove_duplicates(list_one: List[Any], list_two: List[Any]) ->
Tuple[List[Any], List[Any]]
. You should also be able to discuss what defect(s)
you found in the remove_duplicates
function and how you fixed them.
Project Assessment¶
Since this project is source code survey, it is aligned with the remembering and understanding levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet the project's specification.
Note
Before you finish all of the required deliverables required by this project is worth pausing to remember that the instructor will give advance feedback to any learner who requests it through GitHub and Discord at least 24 hours before the project's due date! Seriously, did you catch that? This policy means that you can have a thorough understanding of ways to improve your project before its final assessment! To learn more about this opportunity, please read the assessment strategy for this site.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.
Knapsack Solvers¶
Project Goals¶
This assignment invites you to study, repair, and test a Python programs called
demonstrate-knapsack-solvers
. The 0/1 Knapsack problem requires a computer
program to determine which items to pick, from a list of items with both costs
and benefits, in order to maximize the benefits while ensuring that the costs do
not exceed a specified maximum cost. As part of this source code survey you will
will implement and run three different greedy solvers called
greedy-by-density
, greedy-by-weight
, and greedy-by-value
that vary in the
way in which they select items. You will also implement and run an exhaustive
0/1 knapsack solver that is guaranteed to find the optimal solution for a
specific problem instance. With that said, this exhaustive solver must generate
the powerset of the set of all items and is thus only efficient for small
knapsack instances. After running all three of the greedy solvers and then
exhaustive solver you will be able to determine which greedy approach is best
suited for the problem instance.
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to add source code and documentation to the
project and then run the program to learn more about the efficiency and
effectiveness trade-offs associated with different implementations of 0/1
knapsack solvers!
Code Survey¶
If you change into the source/
directory of your GitHub repository, you will
see one Python file called demonstrate-knapsack-solvers.py
. The
demonstrate-knapsack-solvers
module contains an incomplete class definition
written as class Item(object):
. You need to follow the TODO
markers in this
class definition, by inputting the source code from the text book, for functions
like the constructor def __init__(self, n, v, w)
and like accessor functions
such as def get_name(self) -> str
, def get_value(self) -> int
, def
get_weight(self) -> int
. Since your textbook does not provide an implementation
of a function for generating the powerset of a set, you will also need to
consult the references in the source code and create your own function. Finally,
you will need to implement the function that uses the generated powerset to
perform an exhaustive search of all possible combinations of input.
To ensure that the demonstrate-knapsack-solvers.py
script analyzes the same
instance of the 0/1 knapsack problem as is found in the textbook, you should use
the following build_items
function that is also available in the provided
source code. Lines 3
through 5
of this function respectively create the
input to the knapsack solver that includes the name of the item and its value
and weight (i.e., its cost). Lines 6
through 8
of this function populate the
items
List
with all of the previously created instances of Item
. Finally,
the List
of Item
objects returned by this function on line 9
will be
processed by both the greedy and exhaustive solvers.
1 2 3 4 5 6 7 8 9 |
|
After you have addressed all of the TODO
markers inside of the provided source
code, you can run the program by typing the command python
demonstrate-knapsack-solvers.py
as long as you have changed into the source/
directory. If you correctly implemented the program and provided all of the
source code required by the TODO
markers it should produce the following
output. It is important to note that, at least for this instance of the 0/1
knapsack problem, the greedy-by-density
greedy solver produces the solution
that is closest to the optimal one given by the exhaustive solver. It is
important to note that, at least for this instance of the 0/1 knapsack problem,
the greedy-by-density
solver produces the solution that is closest to the
optimal one given by the exhaustive solver. Why do you think that this greedy
solver produced the best solution? Do you think that it is always going to
yield the best solution? Why or why not?
Running all of the knapsack solvers!
Using greedy-by-value to fill knapsack of size 20
Total value of items taken is 200.0
(Computer, 200, 20)
Using greedy-by-weight to fill knapsack of size 20
Total value of items taken is 170.0
(Book, 10, 1)
(Vase, 50, 2)
(Radio, 20, 4)
(Painting, 90, 9)
Using greedy-by-density to fill knapsack of size 20
Total value of items taken is 255.0
(Vase, 50, 2)
(Clock, 175, 10)
(Book, 10, 1)
(Radio, 20, 4)
Generating the powerset of all items!
Using exhaustive enumeration to fill a knapsack of size 20
Total value of items taken is 275.0
(Clock, 175, 10)
(Painting, 90, 9)
(Book, 10, 1)
Running Checks¶
Since this project does not use Poetry to manage
project dependencies and virtual environments, it does not support the use of
commands like poetry run task test
. However, you can leverage the relevant
instructions in the technical
skills to run the command
gatorgrade --config config/gatorgrade.yml
to check your work. If your work
meets the baseline requirements and adheres to the best practices that proactive
programmers adopt you will see that all the checks pass when you run
gatorgrade
. You can study the config/gatorgrade.yml
file in your repository
to learn how
GatorGrade runs
GatorGrader to automatically
check your program and technical writing.
Note
Did you know that GatorGrade and GatorGrader are open-source Python programs implemented by many proactive programmers? If you finish this source code survey and have extra time, please brainstorm some new features that you think these two tools should have, explain your idea by raising an issue in the relevant project's GitHub repository, and take the first step towards implementing and testing your idea. If the maintainers of these tools accept your new feature then you will have helped to improve the experience of other people who use GatorGrade and GatorGrader!
Project Reflection¶
Once you have finished all of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file. Since
this is a source code survey, you should provide output from running each of the
provided Python programs on your own laptop and then explain how the program's
source code produced that output. A specific goal for this project is to ensure
that you can explain the behavior of the greedy solvers called
greedy-by-density
, greedy-by-weight
, and greedy-by-value
. You should also
be able to explain the trade-offs in terms of solution quality and efficiency of
the knapsack solver that uses the exhaustive enumeration strategy.
Project Assessment¶
Since this project is source code survey, it is aligned with the remembering and understanding levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet the project's specification.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.
Ended: Source Code Surveys
Programming Projects ↵
Number Comparison¶
Project Goals¶
This programming project invites you to combine what you learned about the basics of Python programming to implement a useful program that compares three numbers that are provided as input to a program. Specifically, the program should return the largest odd number among the provided inputs, provided that at least one of the number is odd. When none of the input values are odd, the program should return the smallest of the three provided values. Along with adding documentation to the provided source code, you will create your own Python functions that use both iteration constructs and conditional logic to implement a correct program that passes the test suite and all checks. As you enhance your technical skills, you will program with tools such as VS Code and a terminal window and the Python programming language and the Poetry package manager.
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to add source code and documentation to the
project!
Note
If you are an emerging proactive programmer who is not enrolled in a Computer Science class at Allegheny College, you can still work on this assignment! To get started, you should click the "Use this template" button in the number-comparison-starter GitHub repository and create your own version of this project's source code. After creating your GitHub repository, you can follow all of the other steps!
Expected Output¶
This project invites you to implement a number comparison program called
compare
. The program accepts through its command-line three integer values. If
you run the program correctly, it will accept as input the three numbers and
return the largest odd number as long as at least one of the numbers is odd. In
the situation in which none of the numbers are odd, it will return the smallest
number. If you run the program with the command poetry run compare --first 4
--second 10 --third 21
it produces this output:
✨ Comparing the numbers 4, 10, and 21!
Looking for the largest odd number ...
... but if there is no odd number, then ...
... looking for the smallest of the three!
Okay, I found the number 21!
😂 It was nice to find an odd number!
Alternatively, if you run the program with the command poetry run compare
--first 4 --second 10 --third 20
then it produces output like:
✨ Comparing the numbers 4, 10, and 20!
Looking for the largest odd number ...
... but if there is no odd number, then ...
... looking for the smallest of the three!
Okay, I found the number 4!
🤷 Oh well, there were no odd numbers this time!
If you run the program without specifying one of the required input numbers by
using, for instance, the command poetry run compare --first 4 --second 10
then
it will not perform number comparison and instead produce an error message like
the following:
Usage: compare [OPTIONS]
Try 'compare --help' for help.
Error: Missing option '--third'.
To learn more about how to run this program, you can type the command poetry
run compare --help
to see the following output showing how to use compare
:
Usage: compare [OPTIONS]
Perform number comparison to find the largest odd number.
Options:
--first INTEGER [required]
--second INTEGER [required]
--third INTEGER [required]
--install-completion Install completion for the current shell.
--show-completion Show completion for the current shell, to copy it
or customize the installation.
--help Show this message and exit.
Please note that the provided source code does not contain all of the
functionality to produce this output. As explained in the next section, you are
invited to add all of the missing features and ensure that compare
produces
the expected output. Once the program is working correctly, it should produce
all of the expected output described in this section.
Note
Don't forget that if you want to run the compare
program you must use your
terminal window to first go into the GitHub repository containing this
project and then go into the compare
directory that contains the project's
source code. Finally, remember that before running the program you must run
poetry install
to add the dependencies.
Adding Functionality¶
If you study the file compare/compare/main.py
you will see that it has many
TODO
markers that designate the parts of the program that you need to
implement before compare
will produce correct output. If you run the provided
test suite with the command poetry run task test
you will see that it produces
output like the following:
def test_find_minimum():
"""Confirm that the function can find the minimum of three values."""
minimum = main.get_minimum(3, 4, 5)
> assert minimum == 3
E assert None == 3
tests/test_compare.py:16: AssertionError
Alternatively, running the program with a command like poetry run compare
--first 4 --second 10 --third 21
will not produce any output because compare
is missing this functionality! As you complete the tasks near each of the TODO
markers, all while following the relevant instructions in the description of the
technical skills, you should
have a version of compare
that produces all of the expected output.
The compare
program uses the get_minimum
function to identify the minimum of
three int values. You can read a test case in the test_compare.py
test suite
to learn more about how compare
's get_minimum
function should work. For
instance, the following test case confirms that when get_minimum
receives the
inputs 3
, 4
, and 5
then it should return the value of 3
, regardless of
the order in which the values are input to the function. Studying the source
code of test_find_minimum
shows that lines 3
, 5
, and 7
call the
get_minimum
function with different orders of the same input values and lines
4
, 6
, and 8
all confirm that the returned value of minimum
is 3
.
1 2 3 4 5 6 7 8 |
|
If the get_minimum
function works correctly, then you can start to implement
and test the get_largest_odd
function in the compare
program! You can read
some test cases in test_compare.py
test suite to learn more about how
get_largest_odd
should work. For example, the following test case confirms
that when get_largest_odd
receives the values 21
, 4
, and 17
it will
return 21
. In contrast, if it receives the inputs 21
, 4
, and 117
it will
return the value of 117
because that number is also odd and larger than 21
!
1 2 3 4 5 6 7 8 |
|
In summary, you should implement the following functions for the compare
program:
def get_minimum(first: int, second: int, third: int) -> int
def get_largest_odd(first: int, second: int, third: int) -> Tuple[int, bool]
def compare(first: int = typer.Option(...), second: int = typer.Option(...), third: int = typer.Option(...)) -> None
It is worth noting that the get_largest_odd
function returns two values in the
form of a Tuple[int, bool]
. The first of this function's output values is the
int
result either the largest odd number or the smallest even number. The
second bool
value is a Boolean flag to indicate whether it found an odd number
or not. Specifically, the get_largest_odd
function should return True
if it
found an odd number and return False
otherwise.
Running Checks¶
If you study the source code in the pyproject.toml
file you will see that it
includes a section that specifies different executable tasks like lint
. If
you are in the compare
directory that contains the pyproject.toml
file and
the poetry.lock
file, the tasks in this section make it easy to run commands
like poetry run task lint
to automatically run all of the linters designed to
check the Python source code in your program and its test suite. You can also
use the command poetry run task black
to confirm that your source code
adheres to the industry-standard format defined by black
. If it does not meet
this standard, then you can run the command poetry run black compare tests
or, alternatively, poetry run task fixformat
, and it will reformat the Python
source code!
Along with running tasks like poetry run task lint
, you can leverage the
relevant instructions in the technical
skills to run the command
gatorgrade --config config/gatorgrade.yml
to check your work. If your work
meets the baseline requirements and adheres to the best practices that
proactive programmers adopt you will see that all the checks pass when you run
gatorgrade
. You can study the config/gatorgrade.yml
file in your repository
to learn how the
GatorGrade program runs
GatorGrader
to automatically check your program and technical writing.
If your program has all of the anticipated functionality, you can run the
command poetry run task test
and see that the test suite passes and produces
output as shown in the following output. Can you think of any additional tests
to add to the test suite? If you can, then add them so that you can increase
your confident in program correctness!
collected 4 items
tests/test_compare.py ....
Note
Don't forget that when you commit source code or technical writing to your GitHub repository for this project, it will trigger the run of a GitHub Actions workflow. If you are a student at Allegheny College, then running this workflow consumes build minutes for the course's organization! As such, you should only commit to your repository once you have made substantive changes to your project and you are ready to confirm its correctness. Before you commit to your repository, you can still run checks on your own computer by either using Poetry or Docker and GatorGrader.
Project Reflection¶
Once you have finished all of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file. For
instance, you should provide the output of the Python program in a fenced code
block, explain the meaning of the Python source code segments that you
implemented and tested, compare and contrast different implementations of the
Python function called get_largest_odd
, and answer all of the other questions
about your experiences in completing this project.
Project Assessment¶
Since this is a programming project, it is aligned with the applying and analyzing levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet all aspects of the project's specification.
Note
Before you finish all of the deliverables required by this project is worth pausing to remember that the instructor will give advance feedback to any Allegheny College learner who requests it through GitHub and Discord at least 24 hours before a project's due date! Seriously, did you catch that? This policy means that you can have a thorough understanding of ways to improve your project before its final assessment! To learn more about this opportunity, please read the assessment strategy for this site.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.
Square Roots¶
Project Goals¶
This assignment invites you to implement a program that features multiple algorithms for computing the square root of a number. You will implement two algorithms that use iteration constructs to approximate the square root of a number. For a given step size and a tolerance level saying how close the approximation must be, the exhaustive algorithm check if each possible answer is within a specified tolerance for the square root's approximation. In contrast, the efficient algorithm will use bisection search to rapidly prune the search to the best possible approximation of the number's square root. In addition to adding source code and documentation to the provided Python files, you will conduct an experiment to determine which algorithm is the fastest and estimate by how much it is faster. As you enhance your technical skills and explore the experimental evaluation of algorithms, you will continue to program with tools such as VS Code and a terminal window and the Python programming language and the Poetry package manager.
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to add source code and documentation to the
project!
Note
If you are an emerging proactive programmer who is not enrolled in a Computer Science class at Allegheny College, you can still work on this assignment! To get started, you should click the "Use this template" button in the square-roots-starter GitHub repository and create your own version of this project's source code. After creating your GitHub repository, you can follow all of the other steps!
Expected Output¶
This project invites you to implement a square root calculation program called
squareroot
. The program accepts through its command-line a single integer
value for which it will compute the square root using either an efficient
or
an exhaustive
approach. Finally, the squareroot
program offers a --profile
flag that causes it to use the
Pyinstrument package to collect
timing information about the efficiency of the chosen method. If you use Poetry
to run the program with the command poetry run squareroot --number 25000
--approach exhaustive --profile
it produces the following output:
🧮 Attempting to calculate the square root of 25000!
✨ Was this search for the square root successful? Yes
✨ How many guesses did it take to compute the solution? 1581139
✨ The best approximation for the square root of 25000 is 158.1139000041253
🔬 Here's profile data from performing square root computation on 25000!
_ ._ __/__ _ _ _ _ _/_ Recorded: 10:25:39 Samples: 507
/_//_/// /_\ / //_// / //_'/ // Duration: 0.508 CPU time: 0.508
/ _/ v4.0.3
Program: squareroot --number 25000 --approach exhaustive --profile
0.507 primality squareroot/main.py:106
└─ 0.507 compute_square_root_exhaustive squareroot/main.py:36
├─ 0.396 [self]
└─ 0.111 abs <built-in>:0
[2 frames hidden] <built-in>
If you run the program with the command poetry run squareroot --number 25000
--approach efficient --profile
then it produces output like:
🧮 Attempting to calculate the square root of 25000!
✨ Was this search for the square root successful? Yes
✨ How many guesses did it take to compute the solution? 27
✨ The best approximation for the square root of 25000 is 158.11389312148094
🔬 Here's profile data from performing square root computation on 25000!
_ ._ __/__ _ _ _ _ _/_ Recorded: 10:29:41 Samples: 0
/_//_/// /_\ / //_// / //_'/ // Duration: 0.000 CPU time: 0.000
/ _/ v4.0.3
Program: squareroot --number 25000 --approach efficient --profile
No samples were recorded.
It is worth noting that the exhaustive
algorithm took 1581139
guesses to
approximate the square root of 25000
while the efficient
algorithm only
needed 27
! This shows that efficient
's bisection search algorithm is
significantly faster than the exhaustive
approach. Interestingly, the
Pyinstrument package reports that it
could not record any performance data for squareroot
when the program runs in
efficient
mode. Why do you think that this is the case? Is there any way to
overcome this issue by, for instance, reconfiguring Pyinstrument or changing the
input that you pass to the program? Overall, how much faster is efficient
in
comparison to exhaustive
? You can use the equations and suggestions in the
engineering effort about primality
testing to calculate the
percentage change in execution time when running squareroot
in efficient
mode instead of the exhaustive
mode. Finally, to understand why efficient
is
faster than exhaustive
you should study each function's source code and the
textbook's content.
To learn more about how to run this program, you can type the command poetry
run squareroot --help
to see the following output showing how to use squareroot
:
Usage: squareroot [OPTIONS]
Use iteration to perform square root computation of a number and then
perform profiling to capture execution time.
Options:
--number INTEGER [default: 5]
--profile / --no-profile [default: False]
--approach [exhaustive|efficient]
[default: efficient]
--install-completion Install completion for the current shell.
--show-completion Show completion for the current shell, to
copy it or customize the installation.
--help Show this message and exit.
Please note that the provided source code does not contain all of the
functionality to produce this output. As explained in the next section, you are
invited to add the missing features and ensure that squareroot
produces the
expected output. Once the program is working correctly, it should produce output
similar to that shown in this section.
Note
Don't forget that if you want to run the squareroot
program you must use
your terminal to first go into the GitHub repository containing this project
and then go into the squareroot/
directory that houses the project's code.
Finally, remember that before running the program you must run poetry
install
to add the dependencies.
Adding Functionality¶
If you study the file squareroot/squareroot/main.py
you will see that it has
many TODO
markers that designate the parts of the program that you need to
implement before squareroot
will produce correct output. In summary, you
should implement the following functions for the squareroot
program:
def compute_square_root_exhaustive(x: int, epsilon: float = 0.01) -> Tuple[bool, float, int]
def compute_square_root_efficient(x: int, epsilon: float = 0.01) -> Tuple[bool, float, int]
Importantly, you will notice that both compute_square_root_efficient
and
compute_square_root_exhaustive
accept the same types of inputs and produce the
same types of outputs. In particular, the parameter called x
is the number
whose square root the function will compute and epsilon
is the tolerance
parameter describing how close the approximation of x
's square root must be.
The notation Tuple[bool, float, int]
that describes the output of these
functions shows that they each return three values. The first variable in the
return value is a bool
indicating whether or not the function found an answer
within the tolerance of epsilon
. Finally, the second returned variable is a
float
for the calculated value of the square root and the third one is an
int
for the number of guesses that the algorithm took.
You will also notice that there are some TODO
markers in the squareroot
function of the main
module. In the scope of the conditional logic statement
if approach.value == SquareRootCalculationingApproach.efficient
on lines 1
through 7
, the program should call the function
compute_square_root_efficient
depending on whether the profile
variable
specified on the command-line is True
or False
. If profile
is True
, then
the program should use Pyinstrument to measure its execution time, as
illustrated on lines 3
through 5
. However, if profile
is False
, then the
program should only call the compute_square_root_efficient
as shown on line
7
. As lines 9
through 15
show, the function should take analogous steps
for its exhaustive
mode, calling the compute_square_root_exhaustive
instead
of compute_square_root_efficient
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Once you have correctly resolved all of the TODO
markers in the squareroot
program, it should produce the expected output described in the previous
section. With that said, please bear in mind that, when running squareroot
with the --profile
flag it will produce different profiling data depending on
the performance of your computer.
Running Checks¶
If you study the source code in the pyproject.toml
file you will see that it
includes a section that specifies different executable tasks like
lint
. If you are in the squareroot/
directory that contains the pyproject.toml
file and the poetry.lock
file, the tasks in this section make it easy to run
commands like poetry run task lint
to automatically run all of the linters
designed to check the Python source code in your program and its test suite. You
can also use the command poetry run task black
to confirm that your source
code adheres to the industry-standard format defined by the black
tool. If it
does not adhere to the standard then you can run the command poetry run black
squareroot tests
or, alternatively, poetry run task fixformat
, and it will
automatically reformat the code!
Along with running tasks like poetry run task lint
, you can leverage the
relevant instructions in the technical
skills to run the command
gatorgrade --config config/gatorgrade.yml
to check your work. If your work
meets the baseline requirements and adheres to the best practices that
proactive programmers adopt you will see that all the checks pass when you run
gatorgrade
. You can study the config/gatorgrade.yml
file in your repository
to learn how the
GatorGrade program runs
GatorGrader
to automatically check your program and technical writing.
If your program has all of the anticipated functionality, you can run the
command poetry run task test
and see that the test suite passes and produces
output like this:
collected 3 items
tests/test_squareroot.py ....
Note
Don't forget that when you commit source code or technical writing to your GitHub repository for this project, it will trigger the run of a GitHub Actions workflow. If you are a student at Allegheny College, then running this workflow consumes build minutes for the course's organization! As such, you should only commit to your repository once you have made substantive changes to your project and you are ready to confirm its correctness. Before you commit to your repository, you can still run checks on your own computer by using the GatorGrade program to run GatorGrader.
Project Reflection¶
Once you have finished all of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file. For
instance, you should provide the output of the Python program in a fenced code
block, explain the meaning of the Python source code segments that you
implemented and tested, compare and contrast the performance of different
implementations of the square root calculation, and answer all of the other
questions about your experiences in completing this project.
Project Assessment¶
Since this is a programming project, it is aligned with the applying and analyzing levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet all aspects of the project's specification.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.
Matrix Processing¶
Project Goals¶
This project invites you to implement a matrix
program that processes a
two-dimensional "list of lists" called a matrix. The main feature of the program
is that it can count the number of negative numbers inside of a matrix that it
inputs from a file specified on its command-line. In addition to implementing
part of the command-line interface for matrix
you will add source code that
traverses the input matrix and counts the negative numbers. As you enhance your
technical skills by
implementing and documenting a Python program, you will continue to explore
tools such as VS Code and a terminal window and the Python programming language
and the Poetry package manager.
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to add source code and documentation to the
project!
Note
If you are an emerging proactive programmer who is not enrolled in a Computer Science class at Allegheny College, you can still work on this assignment! To get started, you should click the "Use this template" button in the matrix-starter GitHub repository and create your own version of this project's source code. After creating your GitHub repository, you can follow all of the other steps!
Expected Output¶
As previously mentioned, this project invites you to implement a matrix
processing program program called matrix
. The program accepts through its
command-line interface a matrix-file
parameter that designates a file with a
matrix inside of it and the matrix-dir
that is the directory containing the
specified file. For this project, you should use the matrix.txt
file inside of
the input
directory that contains these contents:
100,19,9,9
10,9,8,7
6,4,2,-1
4,2,0,-1
3,0,-1,-2
-1,-1,-2,-5
After correctly adding all of the required features, you can use Poetry to run
the program with the command poetry run matrix --matrix-dir input --matrix-file
matrix.txt
and see that it it produces the following output:
✨ Searching for negative numbers in a matrix stored in input/matrix.txt!
📦 The matrix contains the following integer values:
--- -- -- --
100 19 9 9
10 9 8 7
6 4 2 -1
4 2 0 -1
3 0 -1 -2
-1 -1 -2 -5
--- -- -- --
🧮 The matrix contains 8 negative numbers!
To learn more about how to run this program, you can type the command poetry
run matrix --help
to see the following output showing how to use matrix
:
╭─ Options ─────────────────────────────────────────────────────────────╮
│ --matrix-dir PATH [default: None] │
│ --matrix-file PATH [default: None] │
│ --install-completion [bash|zsh|fish|powe Install completion │
│ rshell|pwsh] for the specified │
│ shell. │
│ [default: None] │
│ --show-completion [bash|zsh|fish|powe Show completion for │
│ rshell|pwsh] the specified shell, │
│ to copy it or │
│ customize the │
│ installation. │
│ [default: None] │
│ --help Show this message │
│ and exit. │
╰───────────────────────────────────────────────────────────────────────╯
Please note that the provided source code does not contain all of the
functionality to produce this output. As explained in the next section, you are
invited to add the missing features and ensure that matrix
produces the
expected output. Once the program is working correctly, it should produce output
similar to that shown in this section.
Note
Don't forget that if you want to run the matrix
program you must use
your terminal to first go into the GitHub repository containing this project
and then go into the matrix
directory that houses the project's code.
Finally, remember that before running the program you must run poetry
install
to add the dependencies.
Adding Functionality¶
If you study the file matrix/matrix/main.py
you will see that it has many
TODO
markers that designate the parts of the program that you need to
implement before matrix
will produce correct output. Specifically, you should
implement these functions in matrix
:
def confirm_valid_file(file: Path) -> bool
def count_negatives_in_matrix(matrix: List[List[int]]) -> int
def matrix(matrix_dir: Path = typer.Option(None), matrix_file: Path = typer.Option(None)) -> None
Once you have correctly resolved all of the TODO
markers in the matrix
program, it should produce the expected output described in the previous
section. The most important function you need to implement for this project is
count_negatives_in_matrix
, which has a signature indicating that it accepts as
input a List
of List
s that contain int
values (i.e., List[List[int]]
)
and returns as output an int
for the number of negative numbers in the file.
You may assume that the matrix
parameter that is input to the
confirm_valid_file
function is organized such that each row and column of the
matrix
is sorted in a non-increasing order.
The following excerpt of output created by a correct implementation of matrix
,
which was produced through the use of the
python-tabulate package,
illustrates the organization of the input matrix. For instance, note that the
first column of the matrix contains the values 100, 10, 6, 4, 3, -1
which are
organized in a non-increasing manner from the top to the bottom of the matrix.
It is also worth noting that all of the other column in the matrix are also
organized in the same non-increasing fashion. Moreover, the third-from-the-top
row of the matrix contains the values 6, 4, 2, -1
while the last row contains
-1, -1, -2, -5
which are also organized in a non-increasing style.
--- -- -- --
100 19 9 9
10 9 8 7
6 4 2 -1
4 2 0 -1
3 0 -1 -2
-1 -1 -2 -5
--- -- -- --
Note
Before you start to implement the source code required by this project is worth pausing to remember that the instructor will give advance feedback to any learner who requests it through GitHub and Discord at least 24 hours before the project's due date! Seriously, did you catch that? This policy means that you can have a thorough understanding of ways to improve your project before its final assessment! To learn more about this opportunity, please read the assessment strategy for this site.
Running Checks¶
If you study the source code in the pyproject.toml
file you will see that it
includes a section that specifies different executable tasks like lint
. If
you are in the compare
directory that contains the pyproject.toml
file and
the poetry.lock
file, the tasks in this section make it easy to run commands
like poetry run task lint
to automatically run all of the linters designed to
check the Python source code in your program and its test suite. You can also
use the command poetry run task black
to confirm that your source code
adheres to the industry-standard format defined by black
. If it does not meet
this standard, then you can run the command poetry run black compare tests
or, alternatively, poetry run task fixformat
, and it will reformat the Python
source code!
Along with running tasks like poetry run task lint
, you can leverage the
relevant instructions in the technical
skills to run the command
gatorgrade --config config/gatorgrade.yml
to check your work. If your work
meets the baseline requirements and adheres to the best practices that
proactive programmers adopt you will see that all the checks pass when you run
gatorgrade
. You can study the config/gatorgrade.yml
file in your repository
to learn how the
GatorGrade program runs
GatorGrader
to automatically check your program and technical writing.
If your program has all of the anticipated functionality, you can run the
command poetry run task test
and see that the test suite passes and produces
output as shown in the following output. Can you think of any additional tests
to add to the test suite? If you can, then add them so that you can increase
your confident in program correctness!
collected 3 items
tests/test_matrix.py ....
Note
Don't forget that when you commit source code or technical writing to your GitHub repository for this project, it will trigger the run of a GitHub Actions workflow. If you are a student at Allegheny College, then running this workflow consumes build minutes for the course's organization! As such, you should only commit to your repository once you have made substantive changes to your project and you are ready to confirm its correctness. Before you commit to your repository, you can still run checks on your own computer by either using Poetry or Docker and GatorGrader.
Project Reflection¶
Once you have finished all of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file. For
instance, you should provide the output of the Python program in a fenced code
block, explain the meaning of the Python source code segments that you
implemented and tested, compare and contrast the performance of different
implementations of the matrix processing algorithm, and answer all of the other
questions about your experiences in completing this project.
Project Assessment¶
Since this is a programming project, it is aligned with the applying and analyzing levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet all aspects of the project's specification.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.
Ended: Programming Projects
Engineering Efforts ↵
Integer Squaring¶
Project Goals¶
This engineering effort invites you to combine what you learned about the basics
of Python programming to implement a useful program that can compute the square
for all of the integer values stored inside of a file. As part of this project
you will learn how to navigate the source code in a Python file, perform file
input and output using Path
objects from pathlib
, implement Python
functions, and implement and test functions that contain either a for
and or
a while
loops. As you enhance your technical
skills, you will implement
a Python program and write technical content in Markdown while using tools
such as VS Code, a terminal window, the Python programming language, and the
Poetry package manager. Ready for some fun with programming? Okay, let's get
started!
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to add source code and documentation to the
project!
Note
If you are an emerging proactive programmer who is not enrolled in a Computer Science class at Allegheny College, you can still work on this assignment! To get started, you should click the "Use this template" icon in the integer-squaring-starter GitHub repository and create your own version of this project's source code. After creating your GitHub repository, you can follow all of the other steps!
Expected Output¶
This project invites you to implement a number squaring program called square
.
You can install the dependencies for the square
program and ensure that it is
ready to run by using your terminal to type the command poetry install
in the
square/
directory that contains the pyproject.toml
and poetry.lock
files.
The program can accept as input a file of numbers, a directory that contains the
this file, and the name of an approach to squaring an integer. If you run the
program correctly, it will iterate through the file of numbers, compute the
square for each number, and output a complete list of the squared values. For
instance, if you run the program with the command poetry run square --approach
for --directory input --file numbers.txt
it produces this output:
😃 Squaring numbers in a file called input/numbers.txt!
[
5184,
841,
3721,
1764,
1936,
...
]
In addition to having a feature that lets you square numbers using a for
loop,
the square
program can perform the same task by using a while
loop! If you
run the program with the command poetry run square --approach while --directory input
--file numbers.txt
then the program should produce the same output as given
above this paragraph. If you run the command poetry run square --help
you
should see the following output that explains how to use the square
program:
Usage: square [OPTIONS]
Provide a command-line interface for iteratively squaring all integers
in a file.
╭─ Options ─────────────────────────────────────────────────────────────╮
│ --approach [for|while] [default: for] │
│ --directory PATH [default: None] │
│ --file PATH [default: None] │
│ --install-completion Install completion for the │
│ current shell. │
│ --show-completion Show completion for the │
│ current shell, to copy it or │
│ customize the installation. │
│ --help Show this message and exit. │
╰───────────────────────────────────────────────────────────────────────╯
Please note that the provided source code does not contain all of the
functionality to produce this output. As explained in the next section, you are
invited to add all of the missing features and ensure that square
produces the
expected output. Once the program is working correctly, you should also try to
use it when specifying a file that is not available on your computer! For instance,
if you run it with the command poetry run square --approach for --directory input
--file numberswrong.txt
then it will not perform the number squaring and
instead produce the following output:
😃 Squaring numbers in a file called input/numberswrong.txt!
🤷 input/numberswrong.txt was not a valid file! Sorry, cannot square the
numbers!
Note
Don't forget that if you want to run the square
program you must use your
terminal window to first go into the GitHub repository containing this
project and then go into the square/
directory that contains the project's
source code. Finally, remember that before running the program you must run
poetry install
to add the dependencies.
Adding Functionality¶
If you study the file square/square/main.py
you will see that it has many
TODO
markers that designate the parts of the program that you need to
implement before square
will produce correct output. If you run the provided
test suite with the command poetry run task test
you will see that it produces
output like the following:
================================ ERRORS =================================
_________________ ERROR collecting tests/test_square.py _________________
tests/test_square.py:4: in <module>
from square import main
square/main.py:54: in <module>
???
E NameError: name 'cli' is not defined
======================== short test summary info ========================
ERROR tests/test_square.py - NameError: name 'cli' is not defined
!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!
=========================== 1 error in 0.14s ============================
Alternatively, running the program with a command like poetry run square
--approach for --directory input --file numbers.txt
will produce the following
output:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/gkapfham/.asdf/installs/python/3.10.5/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/home/gkapfham/working/teaching/github-classroom/proactive-programmers/data-abstraction/starters/engineering-efforts/integer-squaring-starter/square/square/main.py", line 54, in <module>
@cli.command()
NameError: name 'cli' is not defined
This output suggests that the cli
variable was not correctly defined! After
correctly resolving this issue --- all while following the relevant instructions
in the description of the technical
skills --- you should find
the other TODO
markers and correctly resolve them. For instance, you can add
this function to the main.py
file:
1 2 3 4 5 6 7 8 9 |
|
Line 1
of this function defines the signature of confirm_valid_file
, showing
that it will take as input a Path
object and return as output a bool
to
indicate whether or not the file is valid. Lines 4
through 7
confirm that
the file
is valid and True
if it is both not None
and a valid file.
Alternatively, line 9
returns False
to indicate that file
is not valid. In
addition to confirm_valid_file
, you must also implement these functions:
def compute_square_while(value: int) -> int
def compute_square_for(value: int) -> int
def compute_square_iterative(contents: str, square_function: Callable[[int], int]) -> List[int]:
It is worth noting that the compute_square_iterative
function is a
higher-order function that accepts as one of its inputs the square_function
that should be either compute_square_for
or compute_square_while
. The person
running the square
program can pick which of these functions the program will
call by specifying either for
or while
as one of the program's command-line
arguments. The square
program uses the Typer package and the following source
code to ensure that the program only accepts one of these two options. For
instance, if you try to run the program with the command poetry run square
--approach recursion --directory input --file numbers.txt
it will produce the
following error message because recursion
is not a valid option:
Usage: square [OPTIONS]
Try 'square --help' for help.
╭─ Error ───────────────────────────────────────────────────────────────╮
│ Invalid value for '--approach': 'recursion' is not one of 'for', │
│ 'while'. │
╰───────────────────────────────────────────────────────────────────────╯
The square
program contains the following source code to specify the valid
options:
1 2 3 4 5 |
|
Line 1
of this code segment defines a new class called IntegerSquareApproach
that operates as a enumeration of values. Specifically, an instance of the
IntegerSquareApproach
will have a value
variable that is either equal to
FOR
, designating that the input integer should be squared through iteration
with a for
loop or equal to WHILE
, meaning that it should complete the same
task with a while
loop. The square
program uses the IntegerSquareApproach
to define the acceptable arguments that a person can pass to it through its
command-line interface.
Note
It is possible that you will become overwhelmed by the details associated
with Python programming as you implement all of the required functionality
for the square
program. If you get stuck on any aspect of this project,
take the time to write out a list of steps that you have already taken, a
summary of what worked and did not work, and the current questions that
you have. After taking these important steps, you can share a status
update and ask questions in either the GitHub discussions
forum
or the Proactive Programmers Discord
server. Before you ask your question,
please read the advice concerning how to best participate in the
Proactive Programmers
community.
Running Checks¶
If you study the source code in the pyproject.toml
file you will see that it
includes the following section that specifies different executable tasks like
lint
. If you are in the square
directory that contains the pyproject.toml
file and the poetry.lock
file, the tasks in this section make it easy to run
commands like poetry run task lint
to automatically run all of the linters
designed to check the Python source code in your program and its test suite. You
can also use the command poetry run task black
to confirm that your source
code adheres to the industry-standard format defined by the black
tool. If it
does not adhere to the standard then you can run the command poetry run black
square tests
and it will automatically reformat the source code.
Along with running tasks like poetry run task lint
, you can leverage the
relevant instructions in the technical
skills to run the command
gatorgrade --config config/gatorgrade.yml
to check your work. If your work
meets the baseline requirements and adheres to the best practices that
proactive programmers adopt you will see that all the checks pass when you run
gatorgrade
. You can study the config/gatorgrade.yml
file in your repository
to learn how the
GatorGrade program runs
GatorGrader
to automatically check your program and technical writing.
It is worth noting that the test suite for the square
program is missing a
test case! You can create the missing test case by following the example of the
following test:
1 2 3 4 5 6 7 8 9 10 |
|
This test case takes the following steps:
- Lines
3
through7
: Create anumber_list
multiple-line string with integers for squaring - Line
8
: Defines thesquare_function
to be thecompute_square_for
function inmain
- Line
9
: Callscompute_square_iterative
withnumber_list
andsquare_function
- Line
9
: Stores the output of thecompute_square_iterative
function insquare_list
- Line
10
: Asserts that thesquare_list
variable contains the squares of each number
You should write a new test that follows these steps for the
compute_square_while
function! Finally, please make sure that you explain all
of the steps in these test cases by adding single-line comments to each line in
every test case function.
Note
Don't forget that when you commit source code or technical writing to your
GitHub repository for this project, it will trigger the run of a GitHub
Actions workflow. If you are a student at Allegheny College, then running
this workflow consumes build minutes for the course's organization! As such,
you should only commit to your repository once you have made substantive
changes to your project and you are ready to confirm its correctness. Before
you commit to your repository, you can should run checks on your own computer
by running gatorgrade --config config/gatorgrade.yml
.
Project Reflection¶
Once you have finished both of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file. For
instance, you should provide the output of the Python program in a fenced code
block, explain the meaning of the Python source code segments that you
implemented, and answer all of the other questions about your experiences in
completing this project.
Note
To ensure that you master the technical and professional skills introduced as part of this project you need to participate in deliberate practice that "requires both a clear performance goal and immediate informative feedback".1 After reflecting on the challenges that you faced and identifying areas for improvement, make a list of SMART goals that will enable you to more effectively put a specific technical skill into practice, follow your plan, and continually work to improve.2 You can learn more about how to best reflect on your experiences and improve before starting your next project by reviewing the technical skills that a proactive programmer should master!
Project Assessment¶
Since this project is an engineering effort, it is aligned with the evaluating and creating levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet all aspects of the project's specification.
Note
Before you finish all of the deliverables required by this project is worth pausing to remember that the instructor will give advance feedback to any Allegheny College learner who requests it through GitHub and Discord at least 24 hours before a project's due date! Seriously, did you catch that? This policy means that you can have a thorough understanding of ways to improve your project before its final assessment! To learn more about this opportunity, please read the assessment strategy for this site.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.
-
See Merriam-Webster for the definition of Teaching Tech Together for more details about how to effectively learn technical skills. What practical steps can you take to best ensure that you can master the technical skills of a proactive programmer? ↩
-
See the article called How to write SMART goals for an overview of how to create SMART goals that are specific, measurable, achievable, relevant, and time-bound. In your view, what are the benefits of ensuring that your goals fit into the SMART paradigm? ↩
Primality Testing¶
Project Goals¶
This assignment invites you to implement a program that features multiple algorithms for performing primality testing. You will implement two algorithms that conduct a search to determine whether or not the number input to the program is prime. The exhaustive search algorithm will examine all possible elements of a search space while, in contrast, the efficient one will use extra conditional logic to restrict the search space. In addition to adding source code the provided Python files, you will conduct an experiment to determine which algorithm is the fastest and estimate by how much it is faster. As you enhance your technical skills and explore the experimental evaluation of algorithms, you will continue to program with tools such as VS Code and a terminal window and the Python programming language and the Poetry package manager.
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to add source code and documentation to the
project!
Expected Output¶
This project invites you to implement a number squaring program called
primality
. The program accepts as input a number, like 49979687
, a
description of an approach (that can either be efficient
or exhaustive
), and
a boolean flag to indicate whether or not the program should profile its
execution. When primality
is run in exhaustive
mode it checks all integer
values in range(2, number)
if number
is the integer value subject to
primality testing. After you finish the correct implementation of all the
program's features, running it with the command poetry run primality --number
49979687 --approach efficient --profile
will produce output like the following:
😄 Attempting to determine if 49979687 is a prime number!
✨ What divisors were found? 1, 49979687
✨ Was this a prime number? Yes
🔬 Here's profiling data from performing primality testing on 49979687!
_ ._ __/__ _ _ _ _ _/_ Recorded: 22:10:56 Samples: 1
/_//_/// /_\ / //_// / //_'/ // Duration: 0.870 CPU time: 0.869
/ _/ v4.0.3
Program: primality --number 49979687 --approach efficient --profile
0.870 primality primality/main.py:93
└─ 0.870 primality_test_efficient primality/main.py:77
Did you notice that this program produces profiling data about how long it took
to run the primality
program in efficient
mode with the input 49979687
?
This is because of the fact that it uses the
Pyinstrument program to collect
execution traces and efficiency information about the program. For this run of
the program, it took about 0.870
seconds to determine that 49979687
was a
prime number. Is that fast or not? Well, let's run the primality
program in
exhaustive
mode and measure by how much it is slower! Specifically, running
the command poetry run primality --number 49979687 --approach exhaustive
--profile
produces the following output:
😄 Attempting to determine if 49979687 is a prime number!
✨ What divisors were found? 1, 49979687
✨ Was this a prime number? Yes
🔬 Here's profiling data from performing primality testing on 49979687!
_ ._ __/__ _ _ _ _ _/_ Recorded: 22:34:38 Samples: 1
/_//_/// /_\ / //_// / //_'/ // Duration: 1.739 CPU time: 1.738
/ _/ v4.0.3
Program: primality --number 49979687 --approach exhaustive --profile
1.738 primality primality/main.py:93
└─ 1.738 primality_test_exhaustive primality/main.py:57
If exhaustive
mode of primality
takes 1.738
and efficient
mode only
takes 0.870
, how much faster is efficient
mode compared to exhaustive
? If
\(T_f\) denotes the execution time of efficient
mode and \(T_x\) denotes the
execution time of exhausitve
mode, then the following equation defines
\(T_{\Delta}\), or the percentage change in the execution time when running
primality
in efficient
mode instead of exhaustive
.
Using this equation with the timing values of \(T_x = 1.738\) and \(T_f = 0.87\)
from Pyinstrument shows that efficient
mode is \((1.738
- 0.87) / 1.738 * 100 = 49.9427\) percent faster than exhaustive
mode. When you
check the source code in the GitHub repository for this project you will see
why! Unlike exhaustive
mode, the efficient
mode of primality
does not
check for even divisors of number
bigger than two, instead only determining
if number
is divisible by any odd number in range(3, x, 2)
. In retrospect,
it makes sense that efficient
is about \(50\) percent faster than
exhaustive
because, by not checking the even numbers, it does not do half
of exhaustive
's work.
It is worth noting that you do not have to run primality
in the profile
mode
that uses Pyinstrument. For instance, running the program with poetry run
primality --number 49979687 --approach exhaustive
would run the program in
exhaustive
mode and perform the same computation without collecting the
performance data. You can display primality
's help menu and learn more about
the features it should support by typing poetry run primality --help
to
display the following:
Usage: primality [OPTIONS]
Use iteration to perform primality testing on a number.
Options:
--number INTEGER [default: 5]
--profile / --no-profile [default: False]
--approach [exhaustive|efficient]
[default: efficient]
--install-completion Install completion for the current
shell.
--show-completion Show completion for the current shell,
to copy it or customize the
installation.
--help Show this message and exit.
Please note that the provided source code does not contain all of the
functionality to produce the output displayed in this section. As explain in the
next section, you are invited to add the features needed to ensure that
primality
produces the expected output!
Note
Don't forget that if you want to run the primality
program you must use
your terminal window to first go into the GitHub repository containing this
project and then go into the primality
directory that contains the
project's source code. Finally, remember that before running the program you
must run poetry install
to add its dependencies, such as Pyinstrument,
Pytest, and Rich.
Adding Functionality¶
If you study the file primality/primality/main.py
you will see that it has
many TODO
markers that designate the parts of the program that you need to
implement before primality
will produce correct output. If you run the
provided test suite with the command poetry run task test
you will see that it
produces a message suggesting that there is a syntax error in the program. Along
with creating instances of the Typer
and Profiler
classes, you will need to
resolve all of the syntax errors so that you can run primality
and its test
suite. You must also implement all of these functions:
def human_readable_boolean(answer: bool) -> str
def pretty_print_list(values: Iterable[int]) -> str
def primality_test_exhaustive(x: int) -> Tuple[bool, List[int]]
def primality_test_efficient(x: int) -> Tuple[bool, List[int]]
The following source code illustrates how to use Pyinstrument to collect the
timing information for the execution of the efficient
approach for primality
testing, as implemented in the function primality_test_efficient
. First, line
1
creates an empty primality_tuple
and lines 2
and 3
confirm that the
person using the program requested to profile the execution of the efficient
approach. Using Pyinstrument, line 4
starts the profiler and line 6
stops
it, with line 5
making the call to the primality_test_efficient
function.
When the person running primality
did not use --profile
, then line 8
calls
primality_test_efficient
without using Pyinstrument.
1 2 3 4 5 6 7 8 |
|
Running Checks¶
If you study the source code in the pyproject.toml
file you will see that it
includes the following section that specifies different executable tasks like
lint
. If you are in the primality
directory that contains the pyproject.toml
file and the poetry.lock
file, the tasks in this section make it easy to run
commands like poetry run task lint
to automatically run all of the linters
designed to check the Python source code in your program and its test suite. You
can also use the command poetry run task black
to confirm that your source
code adheres to the industry-standard format defined by the black
tool. If it
does not adhere to the standard then you can run the command poetry run black
primality tests
and it will automatically reformat the source code.
Along with running tasks like poetry run task lint
, you can leverage the
relevant instructions in the technical
skills to run the command
gatorgrade --config config/gatorgrade.yml
to check your work. If your work
meets the baseline requirements and adheres to the best practices that proactive
programmers adopt you will see that all the checks pass when you run
gatorgrade
. You can study the config/gatorgrade.yml
file in your repository
to learn how the
GatorGrade program runs
GatorGrader to
automatically check your program and technical writing. If your program has all
of the anticipated functionality, you can run the command poetry run task test
and see that the test suite produces output like the following. Can you add
comments to test_primality.py
to show that you understand how the tests work?
collected 7 items
tests/test_primality.py .......
Don't forget that this project also comes with other tasks that you can run once
you have used Poetry to install all of the dependencies. For instance, if you
find that your Python source code is not in adherence with the required
formatting rules, you can run poetry run task black
to automatically return it
to the correct format! You can also run commands like poetry run task mypy
to
check the program's use of data types and poetry run task pylint
to ensure
that your source code adheres to other established programming conventions. You
can use these built-in tasks to understand and improve your code's quality! If
you want to run all of the built-in checking tasks you can type poetry run task
all
in the directory that contains the pyproject.toml
file.
Note
Don't forget that when you commit source code or technical writing to your GitHub repository for this project, it will trigger the run of a GitHub Actions workflow. If you are a student at Allegheny College, then running this workflow consumes build minutes for the course's organization! As such, you should only commit to your repository once you have made substantive changes to your project and you are ready to confirm its correctness. Before you commit to your GitHub repository, you can still run checks on your own computer by using Poetry and GatorGrader.
Project Reflection¶
Once you have finished both of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file. For
instance, you should provide the output of the Python program in a fenced code
block, explain the meaning of the Python source code segments that you
implemented, and answer all of the other questions about your experiences in
completing this project. A specific goal of the reflection for this project is
to evaluate the efficiency of the two different modes (i.e., exhaustive
and
efficient
) of the primality
program.
Project Assessment¶
Since this project is an engineering effort, it is aligned with the evaluating and creating levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet all aspects of the project's specification.
Note
Before you finish all of the required deliverables required by this project is worth pausing to remember that the instructor will give advance feedback to any learner who requests it through GitHub and Discord at least 24 hours before the project's due date! Seriously, did you catch that? This policy means that you can have a thorough understanding of ways to improve your project before its final assessment! To learn more about this opportunity, please read the assessment strategy for this site.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.
Intersection Algorithms¶
Project Goals¶
This assignment invites you to implement a program that features multiple
algorithms for computing the intersection between a data container.
Specifically, you will implement and experimentally evaluate the following
intersection algorithms: (i) a list
-based approach with a single for
loop,
(ii) a list
-based approach with a double for
loop, (iii) a tuple
-based
approach with a single for
loop, and (iv) a tuple
-based approach with a
double for
loop. In addition to adding source code to the provided Python
files, you will conduct an experiment to determine which algorithm is the
fastest and estimate by how much it is faster. As you enhance your technical
skills and explore the
experimental evaluation of algorithms, you will continue to program with tools
such as VS Code and a terminal window and the Python programming language and
the Poetry package manager.
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to add source code and documentation to the
project!
Expected Output¶
This project invites you to implement a data container intersection problem
called intersection
. After you finish a correct implementation of all the
program's features, running it with the command poetry run intersection
--number 10000 --maximum 25 --profile --approach ListDouble
will produce output
like the following. This output shows that it took approximately 2.210
seconds
to compute the intersection of two list
s that each contain 10,000
randomly
generated values with the maximum value in each list
being 25
. Importantly,
this invocation of the intersection
program configures it to run the
ListDouble
algorithm that uses a doubly-nested for
loop to compute the
intersection of the list
s. Did you notice that this program produces profiling
data about how long it took to run the intersection
program with the
ListDouble
algorithm? This is because of the fact that it uses the
Pyinstrument package to collect
execution traces and efficiency information about the program.
🔬 Here's profiling data from computing an intersection with random data
containers of 10000!
_ ._ __/__ _ _ _ _ _/_ Recorded: 14:01:19 Samples: 2207
/_//_/// /_\ / //_// / //_'/ // Duration: 2.211 CPU time: 2.203
/ _/ v4.0.3
Program: intersection --number 10000 --maximum 25 --profile --approach ListDouble
2.210 intersection intersection/main.py:99
└─ 2.210 compute_intersection_list_double intersection/main.py:53
├─ 2.051 [self]
└─ 0.159 list.append <built-in>:0
[2 frames hidden] <built-in>
It is worth noting that you do not have to run intersection
in the profile
mode that uses Pyinstrument. For instance, running the program with poetry run
intersection --number 10 --maximum 25 --display --approach ListDouble
would run
the program with the ListDouble
algorithm and perform the same computation
without collecting the performance data. When run with this command,
intersection
would produce output like the following. Note that when the
program is run with the --display
flag and without the --profile
flag it
shows the two input data containers and their computed intersection —
without reporting any details about the efficiency of the algorithm. This mode
is ideal when you want to confirm that your implementation of intersection
is
perform the correct computation and less useful when you are running experiments
to study the program's performance.
✨ Here are the details about the intersection computation!
Performed intersection with:
---> the first data container: [22, 10, 21, 11, 2, 7, 4, 16, 22, 23]
---> the second data container: [16, 17, 23, 24, 12, 4, 21, 1, 18, 19]
Computed the intersection as the data container: [21, 4, 16, 23]
Don't forget that you can display intersection
's help menu and learn more
about its features by typing poetry run intersection --help
to display the
following:
Usage: intersection [OPTIONS]
Compute the intersection of data containers.
Options:
--number INTEGER [default: 5]
--maximum INTEGER [default: 25]
--profile / --no-profile [default: False]
--display / --no-display [default: False]
--approach [ListSingle|TupleSingle|ListDouble|TupleDouble]
[default: TupleSingle]
--install-completion Install completion for the current
shell.
--show-completion Show completion for the current shell,
to copy it or customize the
installation.
--help Show this message and exit.
Please note that the provided source code does not contain all of the
functionality to produce the output displayed in this section. As explained in
the next section, you are invited to add the features needed to ensure that
intersection
produces the expected output!
Note
Don't forget that if you want to run the intersection
program you must use
your terminal window to first go into the GitHub repository containing this
project and then go into the intersection
directory that contains the
project's source code. Finally, remember that before running the program you
must run poetry install
to add its dependencies, such as Pyinstrument,
Pytest, and Rich.
Adding Functionality¶
If you study the file intersection/intersection/main.py
you will see that it
has many TODO
markers that designate the parts of the program that you need to
implement before intersection
will produce correct output. To ensure that the
program works correctly, you must implement all of these functions before you
start to run the experiments.
def generate_random_container(size: int, maximum: int, make_tuple: bool = False) -> Union[List[int], Tuple[int, ...]]
def compute_intersection_list_double(input_one: List[Any], input_two: List[Any]) -> List[Any]
def compute_intersection_list_single(input_one: List[Any], input_two: List[Any]) -> List[Any]
The function called generate_random_container
should automatically create
either a tuple
or a list
of the specified size
and only containing values
that are less than or equal to the maximum
. The function called
compute_intersection_list_single
should follow the implementation strategy of
its counterpart function called compute_intersection_tuple_single
while still
using the functions appropriate for the list
structured type. Moreover, the
compute_intersection_list_double
should follow the implementation of
compute_intersection_tuple_double
except for the fact that it should populate
an list
through the use of a doubly-nested for
loop. As a reference, here is
the source code for the compute_intersection_tuple_single
function:
1 2 3 4 5 6 7 8 9 |
|
According to the type signature of this function on lines 1
and 2
, the
compute_intersection_tuple_single
function accepts as input two tuples
that
can contain Any
type of data and be of an arbitrary size. Lines 6
through
8
of this function show that it uses the combination of a for
loop and an
if
statement to compute the intersection of the tuple
s called input_one
and input_two
. After finding those elements that these tuple
s contain in
common, compute_intersection_tuple_single
returns the result
on line 9
.
Since this function processes tuple
s it is possible that the intersection of
the input parameters will be a result
that contains a value more than once. It
is also worth noting that, since the tuple
structured type is immutable, this
function uses the +=
operator on line 8
to create a new tuple
each time
that it adds data to the result
variable. You will empirically study the
efficiency of this approach!
After finishing your implementation of intersection
you should conduct an
experiment to evaluate the efficiency of the different algorithms that it
provides. You should refer to the writing/reflection.md
file for more details
about the experiment that you should conduct and how you must configure the
intersection
program to collect data. Ultimately, you need to answer the
following three research questions:
- Is the intersection of two data containers faster with a
list
or atuple
? - Is the intersection of two data containers faster with a double or single
for
loop? - Overall, what is the fastest approach for computing the intersection of two data containers?
Running Checks¶
If you study the source code in the pyproject.toml
file you will see that it
includes the following section that specifies different executable tasks like
lint
. If you are in the intersection
directory that contains the
pyproject.toml
file and the poetry.lock
file, the tasks in this section
make it easy to run commands like poetry run task lint
to automatically run
all of the linters designed to check the Python source code in your program and
its test suite. You can also use the command poetry run task black
to confirm
that your source code adheres to the industry-standard format defined by the
black
tool. If it does not adhere to the standard then you can run the
command poetry run task fixformat
and it will automatically reformat the
source code. Make sure to examine the pyproject.toml
file for other convenient
tasks that you can use to both check and improve your project!
Along with running tasks like poetry run task lint
, you can leverage the
relevant instructions in the technical
skills to run the command
gatorgrade --config config/gatorgrade.yml
to check your work. If your work
meets the baseline requirements and adheres to the best practices that proactive
programmers adopt you will see that all the checks pass when you run
gatorgrade
. You can study the config/gatorgrade.yml
file in your repository
to learn how the
GatorGrade program runs
GatorGrader to
automatically check your program and technical writing. If your program has all
of the anticipated functionality, you can run the command poetry run task test
and see that the test suite produces output like the following. Can you add
comments to the test suite to explain how the test cases work?
collected 4 items
tests/test_intersection.py .......
This project comes with other tasks that you can run once you have used Poetry
to install all of the dependencies. For instance, if you find that your Python
source code is not in adherence with the required formatting rules, you can run
poetry run task black
to automatically return it to the correct format! You
can also run commands like poetry run task mypy
to check the program's use of
data types and poetry run task pylint
to ensure that your source code adheres
to other established programming conventions. You can use these built-in tasks
to understand and improve your code's quality!
Note
Don't forget that when you commit source code or technical writing to your GitHub repository for this project, it will trigger the run of a GitHub Actions workflow. If you are a student at Allegheny College, then running this workflow consumes build minutes for the course's organization! As such, you should only commit to your repository once you have made substantive changes to your project and you are ready to confirm its correctness. Before you commit to your GitHub repository, you can still run checks on your own computer by using Poetry and GatorGrader.
Project Reflection¶
Once you have finished both of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file. For
instance, you should provide the output of the Python program in a fenced code
block, explain the meaning of the Python source code segments that you
implemented, and answer all of the other questions about your experiences in
completing this project. A specific goal of the reflection for this project is
to evaluate the efficiency of the different algorithms and data containers
implemented as part of the intersection
program. When you are writing your
performance evaluation make sure that you both explain what performance trends
are evident and why you think the algorithms yield these trends. Finally, you
should reflect on how the experimental evaluation of a program's performance is
more nuanced than you might have initially expected before starting to work on
this project.
Project Assessment¶
Since this project is an engineering effort, it is aligned with the evaluating and creating levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet all aspects of the project's specification.
Note
Before you finish all of the required deliverables required by this project is worth pausing to remember that the instructor will give advance feedback to any learner who requests it through GitHub and Discord at least 24 hours before the project's due date! Seriously, did you catch that? This policy means that you can have a thorough understanding of ways to improve your project before its final assessment! To learn more about this opportunity, please read the assessment strategy for this site.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.
Fibonacci Algorithms¶
Project Goals¶
This assignment invites you to implement a program that features multiple algorithms for computing the numbers in the Fibonacci sequence that is recursively defined by the following equations for the \(n\)-th Fibonacci number \(F(n)\).
This recursive definition of the Fibonacci sequences yields the values \(0, 1, 1, 2, 3, 5, \ldots\) where the value of any Fibonacci number, denoted \(F(n)\), is computed by adding together \(F(n-1)\) and \(F(n-2)\) and the other starting values are defined in the first two equations. Since there are different ways to compute the values in the Fibonacci sequence, this project invites you to implement and evaluate their performance.
Specifically, you will implement and experimentally evaluate the following
Fibonacci algorithms: (i) a list
-based approach that uses iteration, (ii) a
list
-based approach that uses recursion, (iii) a tuple
-based approach that
uses iteration, and (iv) a tuple
-based approach using recursion. Along with
adding source code to the provided Python files, you will conduct an experiment
to determine which algorithm is the fastest and aim to understand why it is the
best based on its choice of a data container (i.e., list
or tuple
) and its
algorithmic approach (i.e., iterative
or recursive
).
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to add source code and documentation to the
project!
Note
If you are an emerging proactive programmer who is not enrolled in a Computer Science class at Allegheny College, you can still work on this assignment! To get started, you should click the "Use this template" icon in the fibonacci-algorithms-starter GitHub repository and create your own version of this project's source code. After creating your GitHub repository, you can follow all of the other steps!
Expected Output¶
This project invites you to implement a Python program, called
fibonaccicreator
, that features different ways to compute all of the numbers
in the Fibonacci sequence up to a specified maximum number. After you finish a
correct implementation of all the program's features, running it with the
command poetry run fibonaccicreator --number 10 --approach recursivelist
--display
, it will produce output like the following.
🧳 Awesome, the chosen type of approach is the recursivelist!
🧮 The program will compute up to the 10th Fibonacci number!
✨ This is the output from the recursivelist function:
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
🤷 So, was this an efficient approach for storing the Fibonacci sequence?
Estimated overall memory according to the operating system:
30.484375 megabytes
Estimated peak memory according to the operating system:
38.78515625 megabytes
Estimated execution time according to the simple timer:
0.01 seconds
This output shows that, for instance, the zeroth Fibonacci number is 0
, the
fifth Fibonacci number is 5
, and the tenth Fibonacci number is 55
. This
program output also shows the amount of memory consumed by the recursive
implementation of the Fibonacci calculation that stores the data in a list
that contains 11 values in it. Importantly, this output also shows that, since
the program had to compute so few of the numbers in the Fibonacci sequence, it
did so in an amount of time that was not measurable by the program's execution
timer. It is worth noting that if you run the fibonaccicreator
to request a
different data container and algorithm combination with a command like poetry
run fibonaccicreator --number 10 --approach iterativetuple --display
it should
produce the same numbers in the Fibonacci sequence. With that said, remember
that if you are running an experiment to evaluate the performance of
fibonaccicreator
when it computes a large Fibonacci number, you should not use
the --display
parameter since it will cause too much output to appear in your
terminal window.
Don't forget that you can display fibonaccicreator
's help menu and learn more
about its features by typing poetry run fibonaccicreator --help
to show the
following output. This help menu shows that fibonaccicreator
also has a
--pyinstrument
flag that enables it to produce a web-based output that shows
the function calls made by the fibonaccicreator
and the performance results
created by the Pyinstrument package.
Usage: fibonaccicreator [OPTIONS]
Create the list of Fibonacci values in a specified approach.
╭─ Options ─────────────────────────────────────────────────────────────╮
│ * --approach TEXT [default: None] │
│ [required] │
│ * --number INTEGER [default: None] │
│ [required] │
│ --display │
│ --pyinstrument │
│ --install-complet… [bash|zsh|fish|pow Install completion │
│ ershell|pwsh] for the specified │
│ shell. │
│ [default: None] │
│ --show-completion [bash|zsh|fish|pow Show completion for │
│ ershell|pwsh] the specified shell, │
│ to copy it or │
│ customize the │
│ installation. │
│ [default: None] │
│ --help Show this message │
│ and exit. │
╰───────────────────────────────────────────────────────────────────────╯
Please note that the provided source code does not contain all of the
functionality to produce the output displayed in this section. As the next
section explains, you should add the features needed to ensure that
fibonaccicreator
produces the expected output!
Note
Don't forget that if you want to run the fibonaccicreator
program you must use
your terminal window to first go into the GitHub repository containing this
project and then go into the fibonaccicreator
directory that contains the
project's source code. Finally, remember that before running the program you
must run poetry install
to add its dependencies, such as Pyinstrument,
Pytest, and Rich.
Adding Functionality¶
If you study the file fibonaccicreator/fibonaccicreator/main.py
you will see
that it has many TODO
markers that designate the parts of the program that you
need to implement before fibonaccicreator
will produce correct output. Once
you complete a task associated with a TODO
marker, make sure that you delete
it and revise the prompt associated with the marker into a meaningful comment.
To ensure that the program works correctly, you must implement all of these
functions in the fibonacci
module:
def fibonacci_recursivelist(number: int) -> List[int]
def fibonacci_recursivetuple(number: int) -> Tuple[int, ...]
def fibonacci_iterativetuple(number: int) -> Tuple[int, ...]
def fibonacci_iterativelist(number: int) -> List[int]
After finishing your implementation of fibonaccicreator
you should conduct an
experiment to evaluate the efficiency of the different algorithms that it
provides. You should refer to the writing/reflection.md
file for more details
about the experiment that you should conduct and how you must configure the
fibonaccicreator
program to collect data. Ultimately, you need to answer the
following three research questions:
- Is the
fibonaccicreator
faster when it uses therecursive
or theiterative
method? - Is the
fibonaccicreator
faster when it stores data in alist
or atuple
data container? - Which configuration of the
fibonaccicreator
is the most memory efficient? - Overall, what is the fastest approach for computing and storing the Fibonacci sequence?
- Overall, are there modes of the
fibonaccicreator
that are less suitable for Python?
Please note that there may be certain configurations of the fibonaccicreator
program that prove to be very slow or prone to crashing if they receive certain
types of inputs. This type of behavior is expected and something that you must
investigate and work around whenever possible as you design and conduct your
experiments. As you are collecting and analyzing the experimental results for
this project, please do not report on performance data values that arise from a
run of the program that crashed during the experiment.
Note
Please note that the fibonaccicreator
program uses Python packages, like
psutil
, that either may not reliably work on certain operating systems or
may produce different output depending on the operating system. If you
experience difficulties with installing one of the dependencies of
fibonaccicreator
or the program produces counter-intuitive results, please
work with the course instructor to develop an alternative plan for
taking performance measurements and running the experiments.
Running Checks¶
If you study the source code in the pyproject.toml
file you will see that it
includes the following section that specifies different executable tasks like
lint
. If you are in the intersection
directory that contains the
pyproject.toml
file and the poetry.lock
file, the tasks in this section
make it easy to run commands like poetry run task lint
to automatically run
all of the linters designed to check the Python source code in your program and
its test suite. You can also use the command poetry run task fixformat
to confirm
that your source code adheres to the industry-standard format defined by the
black
tool. If it does not adhere to the standard then you can run the
command poetry run black primality tests
and it will automatically reformat
the source code.
Along with running tasks like poetry run task lint
, you can leverage the
relevant instructions in the technical
skills to run the command
gatorgrade --config config/gatorgrade.yml
to check your work. If your work
meets the baseline requirements and adheres to the best practices that
proactive programmers adopt you will see that all the checks pass when you run
gatorgrade
. You can study the config/gatorgrade.yml
file in your repository
to learn how the
GatorGrade program runs
GatorGrader
to automatically check your program and technical writing. If your program has
all of the anticipated functionality, you can run the command poetry run task
test
and see that the test suite produces output like the following. Can you
add comments to the test suite to explain how the test cases work? It is worth
noting that the name of the test suite is test_fibonacci
because the
functions mentioned in the previous section exist in the fibonacci
module.
Can you add comments to explain how these tests work? What are the key
components of every test case created with Pytest?
collected 5 items
tests/test_fibonacci.py .....
This project comes with other tasks that you can run once you have used Poetry
to install all of the dependencies. For instance, if you find that your Python
source code is not in adherence with the required formatting rules, you can run
poetry run task black
to automatically return it to the correct format! You
can also run commands like poetry run task mypy
to check the program's use of
data types and poetry run task pylint
to ensure that your source code adheres
to other established programming conventions. You can use these built-in tasks
to understand and improve your code's quality!
Note
Don't forget that when you commit source code or technical writing to your GitHub repository for this project, it will trigger the run of a GitHub Actions workflow. If you are a student at Allegheny College, then running this workflow consumes build minutes for the course's organization! As such, you should only commit to your repository once you have made substantive changes to your project and you are ready to confirm its correctness. Before you commit to your GitHub repository, you can still run checks on your own computer by using Poetry and GatorGrader.
Project Reflection¶
Once you have finished both of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file. For
instance, you should provide the output of the Python program in a fenced code
block, explain the meaning of the Python source code segments that you
implemented, and answer all of the other questions about your experiences in
completing this project. A specific goal of the reflection for this project is
to evaluate the efficiency of the different algorithms and data containers
implemented as part of the fibonaccicreator
program.
In addition to explicitly answering the aforementioned research questions,
please make sure that you explain why the performance trends are evident in your
data by referencing and explaining the source code that implements each of the
algorithms implemented in the fibonaccicreator
. Once you have finished
addressing the prompts in the writing/reflection.md
file that have TODO
makers given as reminders, make sure that you either delete the prompt or
carefully integrate a revised version of it into your writing.
Note
To ensure that you master the technical and professional skills introduced as part of this project you need to participate in deliberate practice that "requires both a clear performance goal and immediate informative feedback".1 After reflecting on the challenges that you faced and identifying areas for improvement, make a list of SMART goals that will enable you to better put a specific technical skill into practice, follow your plan, and work to improve while guided by feedback from peers and experts.2
Project Assessment¶
Since this project is an engineering effort, it is aligned with the evaluating and creating levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet all aspects of the project's specification.
Note
Before you finish all of the required deliverables required by this project is worth pausing to remember that the instructor will give advance feedback to any learner who requests it through GitHub and Discord at least 24 hours before the project's due date! Seriously, did you catch that? This policy means that you can have a thorough understanding of ways to improve your project before its final assessment! To learn more about this opportunity, please read the assessment strategy for this site.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.
-
See Merriam-Webster for the definition of Teaching Tech Together for more details about how to effectively learn technical skills. What practical steps can you take to best ensure that you can master the technical skills of a proactive programmer? ↩
-
See the article called How to write SMART goals for an overview of how to create SMART goals that are specific, measurable, achievable, relevant, and time-bound. In your view, what are the benefits of ensuring that your goals fit into the SMART paradigm? ↩
Palindrome Checking¶
Project Goals¶
This engineering effort invites you to implement a program called
palindromechecker
that can determine whether or not an input word is or is not
a palindrome, or a word that is spelled the same both forwards and backwards.
For instance, the word civic
is a palindrome because it is spelled the same
both forwards and backwards while example
is not. Specifically, you will
implement one approach to palindrome checking that uses recursion and another
that reverses the word. In addition to implementing these two approaches for
palindrome checking, you will create a comprehensive command-line interface
using Typer. Along with implementing your own
test cases for the functions that determine whether the word is a palindrome,
you will also add documentation to your palindromechecker
in the form of
docstrings for both the functions and the module.
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to add source code and documentation to the
project!
Note
If you are an emerging proactive programmer who is not enrolled in a Computer Science class at Allegheny College, you can still work on this assignment! To get started, you should click the "Use this template" button in the palindrome-checker-starter GitHub repository and create your own version of this project's source code. After creating your GitHub repository, you can follow all of the other steps!
Expected Output¶
This project invites you to implement a Python program, called
palindromechecker
, that features different ways determine whether or not a
number is a palindrome. After you finish a correct implementation of all the
program's features, running it with the command poetry run palindromechecker
--word civic --approach recursive
, it will produce this output. See a later
section for more output examples!
✨ Awesome, using the recursive approach for palindrome checking!
🔖 Going to check to see if the word "civic" is a palindrome!
😆 Is this word a palindrome? Yes, it is!
Don't forget that you can display palindromechecker
's help menu and learn more
about its features by typing poetry run palindromechecker --help
to show the
following output. This help menu shows that palindromechecker
has a
--approach
flag that enables it to check whether or not a word is a palindrome
through the use of a reverse
-based or recursive
-based technique.
╭─ Options ─────────────────────────────────────────────────────────────╮
│ * --word TEXT [default: None] │
│ [required] │
│ --approach [recursive|reverse [default: reverse] │
│ ] │
│ --install-complet… [bash|zsh|fish|pow Install completion │
│ ershell|pwsh] for the specified │
│ shell. │
│ [default: None] │
│ --show-completion [bash|zsh|fish|pow Show completion for │
│ ershell|pwsh] the specified shell, │
│ to copy it or │
│ customize the │
│ installation. │
│ [default: None] │
│ --help Show this message │
│ and exit. │
╰───────────────────────────────────────────────────────────────────────╯
Please note that the provided source code does not contain all of the
functionality needed to produce the output displayed in this section and later
in the project description. As the next section explains, you should add the
features needed to ensure that palindromechecker
produces the expected output!
Importantly, this project invites you to add both a recursion-based and
reversal-based algorithm for palindrome checking.
Note
Don't forget that if you want to run the palindromechecker
program you must use
your terminal window to first go into the GitHub repository containing this
project and then go into the palindromechecker
directory that contains the
project's source code. Finally, remember that before running the program you
must run poetry install
to add its dependencies, such as Pyinstrument,
Pytest, and Rich.
Adding Functionality¶
If you study the file palindromechecker/palindromechecker/main.py
you will see
that it has many TODO
markers that designate the parts of the program that you
need to implement before palindromechecker
will produce correct output. Once
you complete a task associated with a TODO
marker, make sure that you delete
it and revise the prompt associated with the marker into a meaningful comment.
To ensure that the program works correctly, you must implement all of these
functions in the palindrome
module:
def to_chars(word: str) -> str
def is_palindrome(word: str) -> bool
def is_palindrome_recursive(word: str) -> bool
is_palindrome_reverse(word: str) -> bool
After finishing your implementation of palindromechecker
you should repeatedly
run the program in different configurations to confirm that it produces the
correct output. Since the palindromechecker
provides a checking mode based on
reversing the string or recursively checking the string, you should make sure
that both approaches work correctly. You should also confirm that the
palindromechecker
can correctly determine when a word both is and is not a
palindrome. Here are some examples that show the program's correct execution for
different values for the --word
and --approach
arguments. If you correctly
resolve all of the TODO
markers in the provided source code your program
should produce the same output for each of these commands.
poetry run palindromechecker --word civic --approach reverse
✨ Awesome, using the recursive approach for palindrome checking!
🔖 Going to check to see if the word "civic" is a palindrome!
😆 Is this word a palindrome? Yes, it is!
poetry run palindromechecker --word civic --approach reverse
✨ Awesome, using the reverse approach for palindrome checking!
🔖 Going to check to see if the word "civic" is a palindrome!
😆 Is this word a palindrome? Yes, it is!
poetry run palindromechecker --word origin --approach recursive
✨ Awesome, using the recursive approach for palindrome checking!
🔖 Going to check to see if the word "origin" is a palindrome!
😆 Is this word a palindrome? No, it is not!
poetry run palindromechecker --word origin --approach reverse
✨ Awesome, using the reverse approach for palindrome checking!
🔖 Going to check to see if the word "origin" is a palindrome!
😆 Is this word a palindrome? No, it is not!
Running Checks¶
If you study the source code in the pyproject.toml
file you will see that it
includes the following section that specifies different executable tasks like
lint
. If you are in the listsorting
directory that contains the
pyproject.toml
file and the poetry.lock
file, the tasks in this section
make it easy to run commands like poetry run task lint
to automatically run
all of the linters designed to check the Python source code in your program and
its test suite. You can also use the command poetry run task black
to confirm
that your source code adheres to the industry-standard format defined by the
black
tool. If it does not adhere to the standard then you can run the
command poetry run task fixformat
and it will automatically reformat the
source code.
Along with running tasks like poetry run task lint
, you can leverage the
relevant instructions in the technical
skills to run the command
gatorgrade --config config/gatorgrade.yml
to check your work. If your work
meets the baseline requirements and adheres to the best practices that
proactive programmers adopt you will see that all the checks pass when you run
gatorgrade
. You can study the config/gatorgrade.yml
file in your repository
to learn how the
GatorGrade program runs
GatorGrader
to automatically check your program and technical writing. If your program has
all of the anticipated functionality, you can run the command poetry run task
test
and see that the test suite produces output like the following. Can you
add comments to explain how these tests work? What are the key components of
every test case created with Pytest? How do the tests "cover" the source code
the of the program?
tests/test_main.py ....
tests/test_palindrome.py ....
tests/test_util.py ..
This project comes with other tasks that you can run once you have used Poetry
to install all of the dependencies. For instance, if you find that your Python
source code is not in adherence with the required formatting rules, you can run
poetry run task fixformat
to automatically return it to the correct format!
You can also run commands like poetry run task mypy
to check the program's use
of data types and poetry run task pylint
to ensure that your source code
adheres to other established programming conventions. You can use these built-in
tasks to understand and improve your code's quality! For this assignment, you
can also use the command poetry run task coverage
to create a coverage report,
like the one shown below, that reveals how well your tests exercise the source
code in the program palindromechecker
program. You should try to write test
cases that completely cover the program's source code, producing a report like
this one.
Name Stmts Miss Cover Missing
---------------------------------------------------------------
palindromechecker/__init__.py 1 0 100%
palindromechecker/main.py 26 0 100%
palindromechecker/palindrome.py 18 0 100%
palindromechecker/util.py 4 0 100%
---------------------------------------------------------------
TOTAL 49 0 100%
Note
Don't forget that when you commit source code or technical writing to your GitHub repository for this project, it will trigger the run of a GitHub Actions workflow. If you are a student at Allegheny College, then running this workflow consumes build minutes for the course's organization! As such, you should only commit to your repository once you have made substantive changes to your project and you are ready to confirm its correctness. Before you commit to your GitHub repository, you can still run checks on your own computer by using Poetry and GatorGrader.
Project Reflection¶
Once you have finished both of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file. For
instance, you should provide the output of the Python program in a fenced code
block, explain the meaning of the Python source code segments that you
implemented, and answer all of the other questions about your experiences in
completing this project. A specific goal of the reflection for this project is
to continue to explore how test cases and test coverage information can help a
developer to both establish a confidence in the correctness of and to find bugs
in a Python program. Once you have finished addressing the prompts in the
writing/reflection.md
file that have TODO
makers given as reminders, make
sure that you either delete the prompt or carefully integrate a revised version
of it into your writing.
Project Assessment¶
Since this project is an engineering effort, it is aligned with the evaluating and creating levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet all aspects of the project's specification.
Note
Before you finish all of the required deliverables required by this project is worth pausing to remember that the instructor will give advance feedback to any learner who requests it through GitHub and Discord at least 24 hours before the project's due date! Seriously, did you catch that? This policy means that you can have a thorough understanding of ways to improve your project before its final assessment! To learn more about this opportunity, please read the assessment strategy for this site.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.
Object Processing¶
Project Goals¶
This engineering effort invites you to implement and use a program called
objectprocessor
searches a text file for rows of data that match a specific
pattern. The objectprocessor
works by reading in a text file in comma-separate
value (CSV) format that contains information about a person on each row of the
file. Next, the program converts each row of data into an instance of the
Person
class, stores that instance inside of a List
, and then performs one
of several configurable searches for instances of Person
that match the
constraints specified on the command-line of the objectprocessor
. Finally, the
program will save all of the matching rows of data in the specified file. In
addition to implementing the functions that perform the file input and output
and the searching for matching Person
s in the List
, you will use a
comprehensive command-line interface, implemented with
Typer, that allows you to easily to confirm the
files for input and output and the terms for the query for matching people.
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to add source code and documentation to the
project!
Expected Output¶
This project invites you to implement a Python program, called
objectprocessor
, that features different ways search through a text file to
find records that match the parameter values specified on the command-line.
Specifically, the records of data in the specified input file should correspond
to information about a specific person, organized in the following fashion. It
is worth noting that all of the data in the input file is automatically
generated by a tool that uses the Faker
library and is thus synthetic in nature.
Cindy Burns,Dominican Republic,(102)481-3875,"Pharmacist, hospital",rtorres@example.org
Jason Bailey,Falkland Islands (Malvinas),+1-552-912-2326,Leisure centre manager,daniel51@example.com
Andrew Johnson,Portugal,733-554-3949,"Engineer, site",michael94@example.com
Carol Poole,Isle of Man,365.529.7270,Pensions consultant,piercebrenda@example.com
Riley Gonzalez,Libyan Arab Jamahiriya,7752827092,Materials engineer,osborneeric@example.net
After you finish a correct implementation of all the objectprocessor
's
features you can run it with the command poetry run objectprocessor
--search-term tylera --attribute email --input-file input/people.txt
--output-file output/people.txt
and see that it produces output like the
following. It is important to note that since this program is deterministic and
not dependent on the performance characteristics of your computer, your
implementation of the program should produce exactly the following output. This
specific invocation of the program looks for people with records that have an
email address containing the search term tylera
. After inputting the 50,000
records from the file called input/people.txt
and converting each one to an
object-oriented format, the program searches and ultimately determines that
there are four people in the input file that match the search parameters.
🧮 Reading in the data from the specified file input/people.txt
🚀 Parsing the data file and transforming it into people objects
🕵 Searching for the people with an email that matches the search term
'tylera'
✨ Here are the matching people:
- Debra Williams is a Retail merchandiser who lives in Guadeloupe. You can
call this person at 407-035-6634 and email them at tyleranderson@example.com
- Christopher Lin is a Embryologist, clinical who lives in United Kingdom.
You can call this person at (515)580-8082x35082 and email them at
tyleranthony@example.com
- William Valdez is a Air broker who lives in Algeria. You can call this
person at 408.592.1306 and email them at tylerashley@example.net
- Joshua Chaney is a Water engineer who lives in San Marino. You can call
this person at 310.624.7694x64127 and email them at tylerallen@example.net
✨ Saving the matching people to the file output/people.txt
Finally, don't forget that you can display objectprocessor
's help menu and
learn more about its features by typing poetry run objectprocessor --help
to
show the following output. It is worth noting that all of the parameters to the
objectprocessor
program, excepting those connected to completion of
command-line arguments or the help menu, are required. This means that the
objectprocessor
will produce an error if you do not specify the four required
parameters respectively related to the search term, the "attribute" of a person
stored in a row of data (e.g., the email address or the country), and both the
input file and the output file that will save the search results.
Usage: objectprocessor [OPTIONS]
Input data about a person and then analyze and save it.
╭─ Options ─────────────────────────────────────────────────────────────╮
│ * --search-term TEXT [default: None] [required] │
│ * --attribute TEXT [default: None] [required] │
│ * --input-file PATH [default: None] [required] │
│ * --output-file PATH [default: None] [required] │
│ --install-completion Install completion for the │
│ current shell. │
│ --show-completion Show completion for the current │
│ shell, to copy it or customize │
│ the installation. │
│ --help Show this message and exit. │
╰───────────────────────────────────────────────────────────────────────╯
Please note that the provided source code does not contain all of the
functionality to produce the output displayed in this section. As the next
section explains, you should add the features needed to ensure that
objectprocessor
produces the expected output! Although you don't need to add
any functionality to the person
module, you will need to address all of the
TODO
markers in the process
and main
modules.
Note
Don't forget that if you want to run the objectprocessor
you must use your
terminal window to first go into the GitHub repository containing this
project and then go into the objectprocessor/
directory that contains the
project's source code. Finally, remember that before running the program you
must run poetry install
to add its dependencies, such as Pytest for
automated testing and Rich for colorful output!
Adding Functionality¶
If you study the file objectprocessor/objectprocessor/process.py
you will see
that it has many TODO
markers that designate the sorting algorithms that you
must implement so as to ensure that objectprocessor
will produce correct
output. For instance, you will need to implement most of the steps in the def
extract_person_data(data: str) -> List[person.Person]
function that takes as
input all of the text in the input CSV file and produces as output a List
of
instances of the Person
class in the person
module. You will also need to
implement the both functions that determine if a specific instance of Person
matches the criteria specified on the program's command-line interface and those
that perform the file input and output. Finally, you are invited to implement
the functions in the main
module that call the functions in process
.
Once you complete a task associated with a TODO
marker, make sure that you
delete it and revise the prompt associated with the marker into a meaningful
comment! After you revise all of the TODO
markers your project should feature
polished source code that is ready for contribution to an open-source project or
described on your professional web site. Finally, you will notice that this
project does not come with test cases. If you want to both establish a
confidence in the correctness of and find defects in your program, then you will
need to design, implement, and run your own tests using
Pytest!
Running Checks¶
If you study the source code in the pyproject.toml
file you will see that it
includes a section that specifies different executable tasks like lint
. If
you are in the objectprocessor/
directory that contains the pyproject.toml
file and the poetry.lock
file, the tasks in this section make it easy to run
commands like poetry run task lint
to automatically run all of the linters
designed to check the Python source code in your program and its test suite.
You can also use the command poetry run task black
to confirm that your
source code adheres to the industry-standard format defined by the black
tool. If it does not adhere to the standard then you can run the command
poetry run task fixformat
to automatically reformat the code!
Along with running tasks like poetry run task lint
, you can leverage the
relevant instructions in the technical
skills to run the command
gatorgrade --config config/gatorgrade.yml
to check your work. If your work
meets the baseline requirements and adheres to the best practices that
proactive programmers adopt you will see that all the checks pass when you run
gatorgrade
. You can study the config/gatorgrade.yml
file in your repository
to learn how the
GatorGrade program runs
GatorGrader
to automatically check your program and technical writing.
Note
Don't forget that when you commit source code or technical writing to your GitHub repository for this project, it will trigger the run of a GitHub Actions workflow. If you are a student at Allegheny College, then running this workflow consumes build minutes for the course's organization! As such, you should only commit to your repository once you have made substantive changes to your project and you are ready to confirm its correctness. Before you commit to your repository, you can still run checks on your own computer by using the GatorGrade program to run GatorGrader.
Project Reflection¶
Once you have finished both of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file. For
instance, you should provide the output of the Python program in several fenced
code blocks, explain the meaning of the Python source code segments that you
implemented, and answer all of the other questions about your experiences in
completing this project. A specific goal for this project's reflection is to
ensure that you can explain Python source code written in an object-oriented
fashion and discuss the trade-offs associated with this approach. For instance,
you should understand how the following constructor, implemented in the
__init__
method, is used to create a new instance of the Person
class.
def __init__(
self, name: str, country: str, phone_number: str, job: str, email: str
) -> None:
"""Define the constructor for a person."""
self.name = name
self.country = country
self.phone_number = phone_number
self.job = job
self.email = email
Project Assessment¶
Since this project is an engineering effort, it is aligned with the evaluating and creating levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet all aspects of the project's specification.
Note
Before you finish all of the required deliverables required by this project is worth pausing to remember that the instructor will give advance feedback to any learner who requests it through GitHub and Discord at least 24 hours before the project's due date! Seriously, did you catch that? This policy means that you can have a thorough understanding of ways to improve your project before its final assessment! To learn more about this opportunity, please read the assessment strategy for this site.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.
Sorting Algorithms¶
Project Goals¶
This engineering effort invites you to implement and use a program called
listsorting
that performs a doubling experiment to evaluate the performance of
several different sorting algorithms. First, you will follow the Sorting
Algorithms in Python
tutorial from Real Python and add certain sorting
algorithms, like bubble sort and quick sort, to your project. After you have
implemented all of the required sorting algorithms, you will use the provided
benchmarking framework to conduct a doubling experiment. This doubling
experiment will invoke a specific sorting algorithm while repeatedly doubling
the size of the input to the sorting algorithm for a specific number of doubling
rounds. Since the doubling experiment enables you to calculate a doubling ratio,
it enables you to experimentally predict the likely worst-case time complexity
of each sorting algorithms. In addition to implementing the sorting algorithms
and extending the benchmarking framework, you will use a comprehensive
command-line interface, implemented with Typer,
that allows you to easily control the execution of a doubling experiment.
Finally, you will use your empirical results from using the listsorting
program to better understand the performance trade-offs associated with sorting
algorithms implemented in Python.
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to add source code and documentation to the
project!
Note
If you are an emerging proactive programmer who is not enrolled in a Computer Science class at Allegheny College, you can still work on this assignment! To get started, you should click the "Use this template" button in the sorting-algorithms-starter GitHub repository and create your own version of this project's source code. After creating your GitHub repository, you can follow all of the other steps!
Expected Output¶
This project invites you to implement a Python program, called listsorting
that performs a doubling experiment to evaluate the performance of several
different sorting algorithms. After you finish a correct implementation of all
the program's features, running it with the command poetry run listsorting
--starting-size 100 --number-doubles 5 --approach insertion
, causes it to
produce output like the following. With that said, please remember that when you
run the listsorting
program your computer it will likely produce different
performance results! Importantly, this output shows that the listsorting
program ran the insertion sort algorithm, denoted insertion
, for a total of
5
rounds in a doubling experiment that created input sizes that ranged from
100
to 1600
. When listsorting
runs the experiment, it uses the
timeit package to measure the
min
, max
, and avg
execution time of the algorithm.
✨ Conducting an experiment to measure the performance of list sorting!
The chosen sorting algorithm: insertion
Starting size of the data container: 100
Number of doubles to execute: 5
✨ Here are the results from running the experiment!
Input Size Min time (s) Max time (s) Avg time (s)
------------ -------------- -------------- --------------
100 0.00198 0.00228 0.0021
200 0.00791 0.00831 0.00804
400 0.03091 0.03179 0.03129
800 0.1397 0.14232 0.141
1600 0.56098 0.58918 0.57665
These experimental results suggest that insertion sort has a doubling ratio of
\(\frac{0.57665}{0.141} \approx 4.0897\). If you look at the last row of the data
table you will see that, for the input sizes of 1600
and 800
, the average
execution time for insertion sort was \(0.57665\) and \(0.141\) seconds,
respectively. Dividing the execution time for the larger input size by the
execution time of the smaller input size yields the doubling ratio of
approximately \(4.0897\), suggestion that insertion sort is a \(O(n^2)\) algorithm
because a doubling of the input size caused a quadrupling of the execution time.
Moreover, don't forget that you can display listsorting
's help menu and learn
more about its features by typing poetry run listsorting --help
to show the
following output. Finally, remember that the listsorting
program should also
run experiments for the other sorting algorithms, such as bubble sort and quick
sort! You can also run listsorting
with larger input sizes or more rounds of
input doubling --- but be aware of the fact that your experiments could take a
long time to finish for certain algorithms!
╭─ Options ─────────────────────────────────────────────────────────────╮
│ --starting-size INTEGER [default: 1000000] │
│ --maximum-value INTEGER [default: 10000] │
│ --number-doubles INTEGER [default: 10] │
│ --approach [bubble|insertion|m [default: bubble] │
│ erge|quick|tim] │
│ --install-completion [bash|zsh|fish|powe Install completion │
│ rshell|pwsh] for the specified │
│ shell. │
│ [default: None] │
│ --show-completion [bash|zsh|fish|powe Show completion for │
│ rshell|pwsh] the specified shell, │
│ to copy it or │
│ customize the │
│ installation. │
│ [default: None] │
│ --help Show this message │
│ and exit. │
╰───────────────────────────────────────────────────────────────────────╯
Please note that the provided source code does not contain all of the
functionality to produce the output displayed in this section. As the next
section explains, you should add the features needed to ensure that
listsorting
produces the expected output! Drawing from the source code
provided in the aforementioned Sorting Algorithms in
Python tutorial from Real
Python, this project invites you to add all of the
sorting algorithms, use the listsorting
program to conduct a doubling
experiment for each of the sorting algorithms and, finally, leverage the data
tables of empirical results to calculate a doubling ratio and predict the likely
worst-case time complexity of each sorting algorithm.
Note
Don't forget that if you want to run the listsorting
program you must use
your terminal window to first go into the GitHub repository containing this
project and then go into the listsorting/
directory that contains the
project's source code. Finally, remember that before running the program you
must run poetry install
to add its dependencies, such as Pytest for
automated testing and Rich for colorful output!
Adding Functionality¶
If you study the file listsorting/listsorting/sorting.py
you will see that it
has many TODO
markers that designate the sorting algorithms that you must
implement so as to ensure that listsorting
will produce correct output. For
instance, you will need to provide an implementation of each sorting algorithm,
like bubble sort, that has a signature like def bubble_sort(array: List[int])
-> List[int]
. You will also need to resolve all of the TODO
markers in
listsorting/listsorting/main.py
that involve calling the functions in
listsorting/listsorting/experiment.py
to run each of the steps in a doubling
experiment. Specifically, you must ensure that the listsorting
function in the
main
module calls the following run_sorting_algorithm_experiment_campaign
function. Once you complete a task associated with a TODO
marker, make sure
that you delete it and revise the prompt associated with the marker into a
meaningful comment.
def run_sorting_algorithm_experiment_campaign(
algorithm: str,
starting_size: int,
maximum_value: int,
number_doubles: int,
) -> List[List[Union[int, Tuple[float, float, float]]]]:
data_table = []
while number_doubles > 0:
random_list = generate_random_container(starting_size, maximum_value)
performance_data = run_sorting_algorithm(algorithm, random_list)
data_table_row = [
starting_size,
performance_data[0],
performance_data[1],
performance_data[2],
]
data_table.append(data_table_row)
number_doubles = number_doubles - 1
starting_size = starting_size * 2
return data_table
Notably, the run_sorting_algorithm_experiment_campaign
function completes all
of the steps associated with running a specified sorting algorithm in a doubling
experiment. Upon completion, this function returns a data_table
that contains
performance results for each round of the doubling experiment, as shown in the
previous section. After finishing your implementation of listsorting
,
including the call to run_sorting_algorithm_experiment_campaign
in main
, you
should repeatedly run the program in different configurations to conduct an
experiment to evaluate the performance of each sorting algorithm that you
implemented. This process will result in a data table that summarizes the
results from a doubling experiment for each sorting algorithm. You can use the
data in the table to calculate the doubling ratio and then use it to predict the
likely worst-case time complexity of each sorting algorithm.
Running Checks¶
If you study the source code in the pyproject.toml
file you will see that it
includes the following section that specifies different executable tasks like
lint
. If you are in the listsorting
directory that contains the
pyproject.toml
file and the poetry.lock
file, the tasks in this section
make it easy to run commands like poetry run task lint
to automatically run
all of the linters designed to check the Python source code in your program and
its test suite. You can also use the command poetry run task black
to confirm
that your source code adheres to the industry-standard format defined by the
black
tool. If it does not adhere to the standard then you can run the
command poetry run task fixformat
and it will automatically reformat the
source code. You can use these and other built-in tasks to understand and
improve your code's quality!
Along with running tasks like poetry run task lint
, you can leverage the
relevant instructions in the technical
skills to run the command
gatorgrade --config config/gatorgrade.yml
to check your work. If your work
meets the baseline requirements and adheres to the best practices that
proactive programmers adopt you will see that all the checks pass when you run
gatorgrade
. You can study the config/gatorgrade.yml
file in your repository
to learn how the
GatorGrade program runs
GatorGrader
to automatically check your program and technical writing. If your program has
all of the anticipated functionality, you can run the command poetry run task
test
and see that the test suite produces output like the following. Can you
add comments to the test suite to explain how the test cases work? It is worth
noting that the name of the test suite is test_sorting
because the
functions mentioned in the previous section exist in the listsorting
module.
Can you add comments to explain how these tests work? What are the key
components of every test case created with Pytest?
tests/test_sorting.py ...
Note
Don't forget that when you commit source code or technical writing to your GitHub repository for this project, it will trigger the run of a GitHub Actions workflow. If you are a student at Allegheny College, then running this workflow consumes build minutes for the course's organization! As such, you should only commit to your repository once you have made substantive changes to your project and you are ready to confirm its correctness. Before you commit to your GitHub repository, you can still run checks on your own computer by using Poetry and GatorGrader.
Project Reflection¶
Once you have finished both of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file. For
instance, you should provide the output of the Python program in a fenced code
block, explain the meaning of the Python source code segments that you
implemented, and answer all of the other questions about your experiences in
completing this project. A specific goal of the reflection for this project is
to ensure that you can clearly write research questions and an experiment
methodology for assessing the performance of a sorting algorithm through a
doubling experiment. Once you have finished addressing the prompts in the
writing/reflection.md
file that have TODO
makers given as reminders, make
sure that you either delete the prompt or carefully integrate a revised version
of it into your writing.
Project Assessment¶
Since this project is an engineering effort, it is aligned with the evaluating and creating levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet all aspects of the project's specification.
Note
Before you finish all of the required deliverables required by this project is worth pausing to remember that the instructor will give advance feedback to any learner who requests it through GitHub and Discord at least 24 hours before the project's due date! Seriously, did you catch that? This policy means that you can have a thorough understanding of ways to improve your project before its final assessment! To learn more about this opportunity, please read the assessment strategy for this site.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.
Containment Checks¶
Project Goals¶
This engineering effort invites you to implement and use a program called
containmentcheck
that conducts an experiment to evaluate the performance of
containment checking using the in
operator for different types of data
containers like tuples and lists. When you run the completed version of the
containmentcheck
program it will allow you to specify the size of the
container, the maximum value of the integer values stored in the container, the
type of data container, and whether or not the searching algorithm should look
for a value that does or does not exceed the maximum value in the list. If you
configure it correctly, the containmentcheck
program will total and average
time for using the in
operator for the automatically generated lists.
Specifically, containmentcheck
will use the
timeit package to measure the
performance of the in
operator for different data containers, following one
of the approaches outlined in the article called measure execution time with
timeit in Python. As you
complete this engineering effort you will experimentally evaluate the claims
in the following articles about the best way to determine if a specific value
exists inside of a data container.
- Membership testing
- Python speed
- Using key in list to check if key is contained in list
- Why is a set faster than a list in Python?
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to add source code and documentation to the
project!
Note
If you are an emerging proactive programmer who is not enrolled in a Computer Science class at Allegheny College, you can still work on this assignment! To get started, you should click the "Use this template" button in the containment-checking-starter GitHub repository and create your own version of this project's source code. After creating your GitHub repository, you can follow all of the other steps!
Expected Output¶
After you finish a correct implementation of all the containmentcheck
's
features you can run it with the command poetry run containmentcheck --size
32000000 --maximum 50000000 --approach list
and see that it produces output
like the following. It is worth noting that your invocation of the program will
likely produce different results than those provided because of the fact that
your laptop may have different software and hardware, and thus different
performance characteristics, than the one used to run containmentcheck
. With
that said, a finished version of containmentcheck
should report both the total
and average time for use the in
operator for the specified data container and
searching approach.
✨ Conducting an experiment to measure the performance of containment checking!
Type of the data container: list
Size of the data container: 32000000
Maximum value for a number in the data container: 50000000
Should the value to search for exceed the maximum number? No
🧮 Total time for running 10 runs in 3 benchmark campaigns: [0.016107587000078638, 0.016178363999642897, 0.016164254000614164]
🧮 Average time for running 10 runs in 3 benchmark campaigns: [0.0016107587000078639, 0.0016178363999642897, 0.0016164254000614164]
Finally, don't forget that you can display containmentcheck
's help menu and
learn more about its features by typing poetry run containmentcheck --help
to
show the following output. It is worth noting that all of the parameters to the
containmentcheck
program, excepting those connected to completion of
command-line arguments or the help menu, are required. This means that the
containmentcheck
will produce an error if you do not specify the four required
parameters that describe the experiment.
╭─ Options ─────────────────────────────────────────────────────────────╮
│ --size INTEGER [default: 5] │
│ --maximum INTEGER [default: 25] │
│ --exceed --no-exceed [default: │
│ no-exceed] │
│ --approach [list|set|tuple [default: list] │
│ ] │
│ --install-compl… [bash|zsh|fish| Install │
│ powershell|pwsh completion for │
│ ] the specified │
│ shell. │
│ [default: None] │
│ --show-completi… [bash|zsh|fish| Show completion │
│ powershell|pwsh for the specified │
│ ] shell, to copy it │
│ or customize the │
│ installation. │
│ [default: None] │
│ --help Show this message │
│ and exit. │
╰───────────────────────────────────────────────────────────────────────╯
Please note that the provided source code does not contain all of the
functionality to produce the output displayed in this section. As the next
section explains, you should add the features needed to ensure that
containmentcheck
produces the expected output! After implementing a function
that can automatically generate a data container that has random numerical
values inside of it, you will need to create each of the containment checking
functions for all of the supported data containers (i.e., list
, tuple
, and
set
).
Note
Don't forget that if you want to run the containmentcheck
you must use your
terminal window to first go into the GitHub repository containing this
project and then go into the containmentcheck/
directory that contains the
project's source code. Finally, remember that before running the program you
must run poetry install
to add its dependencies, such as Pytest for
automated testing and Rich for colorful output!
Adding Functionality¶
If you study the file containmentcheck/containmentcheck/main.py
you will see
that it has many TODO
markers that designate the functions you must implement
so as to ensure that containmentcheck
runs the desired experiment and produces
the correct output. Once you complete a task associated with a TODO
marker,
make sure that you delete it and revise the prompt associated with the marker
into a meaningful comment. Specifically, you will need to implement the
following Python functions:
-
def generate_random_number(maximum: int, exceed: bool = False) -> int
: automatically create a random number starting at zero and going up to themaximum
value. Whenexceed
istrue
the function should generate a number that is greater than the specified maximum value. -
def generate_random_container(size: int, maximum: int, make_tuple: bool = False) -> Union[List[int], Tuple[int, ...]]
: automatically generate a data container that must be either of typeList
or typeTuple
, ensuring that it contains exactlysize
numbers that are never bigger than the specifiedmaximum
. -
def containment_check_list(thelist: List[int], number: int) -> bool
: use thein
operator to perform containment checking for the provided list. -
def containment_check_tuple(thetuple: Tuple[int], number: int) -> bool
: use thein
operator to perform containment checking for the provided tuple. -
def containment_check_set(thelist: List[int], number: int) -> bool
: after converting the provided list to a set, use thein
operator to perform containment checking for the set. This function will allow you to experimentally evaluate the conventional wisdom that a developer can improve the performance of their Python program by converting alist
to aset
before using thein
operator.
Ultimately, you should design your own experiment and state and run experiments to answer your own research questions, focusing on the following key issues:
- The data container:
set
,list
, andtuple
- The size of the data container: small values (e.g., 1 million numbers) to big values (e.g., 32 million numbers)
- Whether or not the value that it being searched for is
in
the list - The maximum value of the numbers that are inside of the data container
Running Checks¶
If you study the source code in the pyproject.toml
file you will see that it
includes the following section that specifies different executable tasks like
lint
. If you are in the containmentcheck
directory that contains the
pyproject.toml
file and the poetry.lock
file, the tasks in this section
make it easy to run commands like poetry run task lint
to automatically run
all of the linters designed to check the Python source code in your program and
its test suite. You can also use the command poetry run task black
to confirm
that your source code adheres to the industry-standard format defined by the
black
tool. If it does not adhere to the standard then you can run the
command poetry run task fixformat
and it will automatically reformat the
source code. You can use these and other built-in tasks to understand and
improve your code's quality!
Along with running tasks like poetry run task lint
, you can leverage the
relevant instructions in the technical
skills to run the command
gatorgrade --config config/gatorgrade.yml
to check your work. If your work
meets the baseline requirements and adheres to the best practices that proactive
programmers adopt you will see that all the checks pass when you run
gatorgrade
. You can study the config/gatorgrade.yml
file in your repository
to learn how the
GatorGrade program runs
GatorGrader to
automatically check your program and technical writing. Please note that this
project is not accompanied by any automated test cases! Can you implement some
tests to confirm that the containment checks work correctly?
Note
Don't forget that when you commit source code or technical writing to your GitHub repository for this project, it will trigger the run of a GitHub Actions workflow. If you are a student at Allegheny College, then running this workflow consumes build minutes for the course's organization! As such, you should only commit to your repository once you have made substantive changes to your project and you are ready to confirm its correctness. Before you commit to your GitHub repository, you can still run checks on your own computer by using Poetry and GatorGrader.
Project Reflection¶
Once you have finished both of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file. For
instance, you should provide the output of the Python program in several fenced
code blocks, explain the meaning of the Python source code segments that you
implemented, and answer all of the other questions about your experiences in
completing this project. A specific goal for this project's reflection is to
ensure that you can explain Python source code that uses the
timeit package to evaluate the
performance of a specific approach to containment checking, as illustrated by
the following code segment. Can you explain this source code?
number_runs = 10
number_repeats = 3
execution_times = timeit.Timer(containment_check_lambda).repeat(
repeat=number_repeats, number=number_runs
Project Assessment¶
Since this project is an engineering effort, it is aligned with the evaluating and creating levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet all aspects of the project's specification.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.
Ended: Engineering Efforts
Ended: Data Abstraction
Discrete Structures ↵
Introduction¶
Quote
"The mathematics of modern computer science is built almost entirely on discrete mathematics, in particular combinatorics and graph theory." David Patrick for the Art of Problem Solving in Why Discrete Mathematics is Important
When software engineers design and implement computer programs, they use, for instance, higher-order, lambda, and generating functions to create and manipulation of discrete structures (e.g., numbers, lists, and dictionaries) that have distinct values. When engineers describe a discrete structure using formal mathematical notation, it better enables them to see both the trade-offs in the structure's design and implementation and the connection between one structure and another. As pointed out by the The Art of Problem Solving team in the article Why Discrete Mathematics is Important, "the mathematics of modern computer science is built almost entirely on discrete mathematics." This course will give you a foundation in both programming and discrete mathematics!
In the context of Python programming, this course teaches you how to use functions and the discrete structures that form their input and output. Leveraging this knowledge of discrete structures and functions, you will learn how to read and translate concepts expressed in natural language, formal mathematical notation, and Python programs. Positioning you for successful work in both theoretical and practical computer science, this course imparts to a learner an applied understanding of topics like Boolean logic, set theory, and probability theory. You will combine your knowledge of the aforementioned topics as you specify, design, document, implement, and test Python programs that employ the best practices for efficiency, correctness, and understandability.
Let's first proactively explore the learning objectives for a course in discrete structures!
Learning Objectives¶
A proactive programmer studying discrete structures should demonstrate the mastery of these learning objectives in the categories of mathematical communication, rigorous programming, and effective communication. According to Robert Talbert, a learning objective must be "a clear, measurable action that a student should be able to do once the lesson is over".1 For the purposes of this site, these learning objectives are not for a specific lesson but rather an entire course for either an Allegheny College student or, for the duration of self-paced learning, all other emerging proactive programmers.
Mathematical Communication¶
A person learning discrete structures with the mindset of a proactive programmer will be able to demonstrate mastery of the following mathematical communication skills:
Discrete Structures¶
- Given the opportunity to input, store, and output a type of data, pick the
correct discrete structure (e.g., a number, set, sequence, stream, dictionary,
or tree) and then:
- Import it and then integrate it into a correct, well-tested, and well-documented Python program consisting of between one hundred and five hundred lines of code.
- Use formal and precise mathematical language to correctly describe the representation, behavior, and limitations of the type of data.
- Justify the decision to use a specific discrete structure to solve a problem.
- Given the formal definition of a discrete structure that is described with mathematical notation, correctly translate it into a Python program, bearing in mind the ways in which the working system may diverge from the formal definition due to, for instance, implementation concerns related to computational costs and storage overheads.
- Given the formal definition of a discrete structure and its implementation as a Python program, correctly describe its properties, demonstrate and verify those properties through testing and/or proof, describe how these properties are similar to and/or different from other discrete structures, and explain when it is appropriate to use the structure.
-
Complete Python programming tasks with a discrete structure. For instance:
- Using the formal definition of Boolean logic operations like
and
,or
, andimplies
, translate a truth table discrete structure into an equivalent implementation in a Python program that uses conditional logic, function definitions, and function calls. - Use the formal definition of a monoid to describe and predict the output of operations (e.g., concatenation) on textual strings in the Python programming language.
- Use the formal definition of a monoid to describe and predict the output of operations (e.g., concatenation) on finite and infinite streams in a Python program.
- Use the formal definition of a set and set-theoretic operations like union, intersection, and containment check to implement a Python program that stores data in a set and correctly manipulates the data using the aforementioned operations.
- Given the formal definition of the domain and range of a mathematical function, implement that function as either a traditional Python function or a dictionary.
- Using the formal definition of Boolean logic operations like
Mathematical Functions¶
- Leveraging an understanding of higher-order functions, lambda functions, and
generating functions, use a problem statement involving one or more discrete
structures to:
- Translate the formal notation and equations used in the problem statement to an algorithm that describes, in a step-by-step fashion, how to solve the problem.
- Pick the most suitable type of function(s) for the problem, implement it in an industry-standard manner using the Python programming language, and then use testing to demonstrate its correctness and experimentation to evaluate its performance.
- After implementing a function in Python using, for instance, higher-order
functions like
map
,reduce
, andfilter
, translate that to an equivalent implementation using, for instance, lambda functions and/or traditional Python functions. - After using Python type annotations to precisely document the type and structure of the input and output of a Python function, use a type checker to confirm that all of the functions in a program communicate with each other in a type-safe fashion.
- Use formal statements to defend the validity of the design, implementation, and testing decisions made when solving a problem with the chosen function(s).
Data Analysis¶
- Given one or more sets of textual, numerical, categorical, binary, or combined
data (that may have missing and/or corrupted data values), implement, test,
use, and evaluate a Python function that supports data analysis through the
completion of these steps:
- Input, process, check, and clean the data sets to confirm their correctness.
- Run an appropriate statistical technique (e.g., the calculation of a mean, median, or standard deviation) to summarize and analyze the data.
- Use an appropriate data visualization technique that can create graphs and diagrams that highlight the salient properties of the data set (e.g., show the general trends in the data set while drawing attention to the dispersion of values).
- Use statistical analysis and data visualization techniques to identify hidden trends in a data set, supporting the prediction of new data values and properties.
- Implement and use an appropriate data processing method that transforms the data into any format required by any external functions (e.g., convert from JSON to CSV).
Rigorous Programming¶
A person learning discrete structures with the mindset of a proactive programmer will be able to demonstrate mastery of the following programming skills:
Python Programming¶
- Write short Python functions of ten to twenty lines that have the following
characteristics:
- Has function and variable names that adhere to an industry-standard coding style.
- Has descriptive comments for module definition and both the function's declaration and the function's code that adhere to an industry-standard coding style.
- Features a source code format that adheres to an industry-standard coding style.
- Passes an automated test suite, written with an industry-standard framework such as Pytest, showing that it correctly implements the specification for the function.
- Performs the specified operation in an efficient fashion, as determined through experiments that evaluate the function's performance in seconds or milliseconds.
- Correctly uses assignment statements, iteration constructs, conditional logic, function invocation, and function recursion in a way that passes the function's test suite, works efficiently, and conveys the intended function's purpose in a Pythonic fashion.
- Correctly uses discrete structure variables such as numbers, tuples, sets, streams, and sequences in a way that passes the test suite, works efficiently, and conveys the intended purpose of the function in a Pythonic fashion.
- Correctly performs file and console input and output, ensuring that all input and output is displayed and stored correctly, is not corrupted, and is processed efficiently.
- Correctly performs calculations for statistical properties of a data set (e.g., the mean, median, and standard deviation), while also clearly displaying the data, its relevant summarization values, and the interpretation of all statistical properties.
- Write correct Python programs consisting of between one and five hundred lines of source code that correctly solve problems using the aforementioned discrete structures (e.g., number, set, or sequence) and function type (e.g., procedural, functional, and lambda).
- Uses the features of the Python programming language to create classes and objects that solve problems through the use of the object-oriented programming paradigm.
- Implement and run Python programs with the following environments and tools:
- Python programs with dependencies, packaging, and tasks, managed by Poetry.
- Python scripts without external dependencies that are run with the interpreter.
- Jupyter notebooks run through either Jupyter Lite or Google Colab.
- Python code segments run in a read-eval-print loop (REPL) on Jupyter Lite.
Programming Tools¶
- Use a Python programming environment to complete these tasks while
implementing a Python program consisting of between one and five hundred lines
of code:
- Install, upgrade, and use Python 3.8, 3.9, or 3.10 programming environment to create, run, and debug a Python program through a terminal window and/or a text editor.
- Use Poetry to install a Python program's dependencies, create a virtual environment, and run it without error in an isolated and self-contained configuration.
- Use and create a test suite implemented with Pytest to detect a failure in a Python program and then effectively use tools like a text editor and a terminal window to find and fix the fault, ultimately confirming that the Python program no longer contains the fault and that the fix did not compromise other functions in the program.
- Use a text editor like VS Code to implement, test, debug, document, and manage the source code of a Python program, leveraging plugins for workflow enhancement.
Version Control¶
- Use the GitHub platform and the
Git version control system in the following fashion:
- Clone a GitHub repository without error using either a command in a terminal window or an extension for Git integration in a text editor like VS Code.
- Write short and descriptive commit messages that explain the specific way in which a commit changes the source code and documentation in the GitHub repository.
- Navigate reports produced by GitHub Actions so as to determine which aspects of a GitHub repository do and do not adhere to a project's specification.
- Use the GitHub Flow model to implement specific features in a branch of a GitHub repository and then merge that branch to the main one only after all the checks run by GitHub Actions pass as required and code reviews confirm the code's correctness.
- Create and discuss programming and technical writing issues through the use of the GitHub Issue Tracker and the GitHub Discussion Forum, furnishing descriptive titles and problem descriptions that adhere to industry best practices and project templates.
- Submit completed projects that pass all of the instructor-provided and industry-standard checks, as evidenced through the report of a passing build by GitHub Actions.
Technical Communication¶
A person learning discrete structures with the mindset of a proactive programmer will be able to demonstrate mastery of the following technology-mediated communication skills:
-
Follow a systematic process when using resources to implement Python programs:
- After detecting an error in a Python program through the use of tools like GatorGrader or Pytest, develop a satisfactory understanding of the problem's possible root cause and then search sites like Stack Overflow for potential solutions.
- After evaluating suggested solutions to a programming problem that originate from sites like Stack Overflow, develop a way to fix an error in a Python program.
- Independently develop solutions to Python programming problems even if the specific technical challenge that you face was not previously covered in a course session or as part of your prior review of technical content.
-
Use Discord to effectively communicate about technology in the following fashion:
- In the correct public channel, post a question that includes source code segments, screenshots, and a description of the steps taken in an attempt to solve a problem.
- Answer questions that were posted in a public channel, responding with source code segments, screenshots, and links to external references, pointing the proactive programmer who asked the question in the right direction without solving the problem for them and limiting their opportunity to learn more about the topic in question.
- Proactively offer to help others who may need to learn scientific, mathematical, or technical knowledge and skills that a learner has already mastered by sharing the acquired knowledge or skill, how you can be contacted, and how you can best assist.
Improving Objectives¶
As Robert Talbert explains, a learning objective is clear when it is "clear from the students' perspective" and measurable when there is "some way to know whether the objective has been met" or "how far away the learner is from meeting it". Do you see a way in which we can improve the learning objectives for discrete structures? If you do, then please participate in the proactive community by sharing your ideas for improving them!
-
See Robert Talbert's article entitled How to Write Learning Objectives for more details about how to design learning objectives for an academic course. From your perspective what does it mean to write learning objectives that are both clear and measurable? ↩
Course Syllabus¶
Computer Science 102 Spring 2023¶
Course Instructor¶
- Name: Dr. Gregory M. Kapfhammer
- Office Location: Alden Hall 108
Instructor Office Hours¶
- Monday: 10:00 AM-11:00 AM, Alden Hall, 15 minute time slots
- Monday: 3:00 PM-4:00 PM, Alden Hall, 15 minute time slots
- Tuesday: 3:00 AM-4:00 AM, Alden Hall, 15 minute time slots
- Wednesday: 11:00 AM-12:00 noon, Alden Hall, 15 minute time slots
- Wednesday: 3:00 PM-5:00 PM, Alden Hall, 15 minute time slots
Scheduling Office Hours
To schedule a meeting with the course instructor during his office hours, please visit the schedule page of his web site and click the "Schedule an Appointment" link at the top of the page. Now you can schedule an appointment by clicking a suitable box in Google Calendar and then reserving an open time slot. At this point, the details about your chosen appointment will appear in both your Google Calendar and the instructor's Google Calendar. Please arrive five minutes in advance for your meeting and be aware that, by necessity, the meeting before yours may sometimes run late.
Course Meeting Schedule¶
- Discussion and Group Work Session: Monday and Wednesday, 9:00 AM-9:50 AM
- Programming Session: Friday, 9:00 AM-9:50 AM
- Laboratory Session: Friday, 2:30 PM-4:20 PM
Course Description¶
An introduction to the foundations of computer science with an emphasis on understanding the abstract structures used to represent discrete objects. Participating in hands-on activities that often require teamwork, students learn the computational methods and logical principles that they need to create and manipulate discrete objects in a programming environment. Students also learn how to write, organize, and document a program's source code so that it is easily accessible to intended users of varied backgrounds. During a weekly laboratory session students use state-of-the-art technology to complete projects, reporting on their results through both written documents and oral presentations. Students are invited to use their own departmentally approved laptop in this course; a limited number of laptops are available for use during class and lab sessions. Prerequisite: Knowledge of elementary algebra.
- Prerequisite: CMPSC 100 or permission of the instructor.
- Distribution Requirements: QR, SP.
Required Textbook¶
- Programming and Mathematical Thinking: A Gentle Introduction to Discrete Math Featuring Python by Allan M. Stavely
- Doing Math with Python: Using Programming to Explore Algebra, Statistics, and More by Amit Saha
Course Schedule¶
- Week One: January 16 to January 20: Software Operation
- Week Two: January 23 to January 27: Making Connections
- Week Three: January 30 to February 3: Programming Constructs
- Week Four: February 6 to February 10: Python Functions
- Week Five: February 13 to February 17: Proactive Review
- Executable Examination One: February 17 during the laboratory session
- Relevant Modules:
- Week Six: February 20 to February 24: Data Containers
- Week Seven: February 27 to March 3: Using Monoids
- Week Eight: March 6 to March 10: Spring Break
- Week Nine: March 13 to March 17: Data Streams
- Week Ten: March 20 to March 24: Set Foundations
- Week Eleven: March 27 to March 31: Proactive Review
- Executable Examination Two: March 31 during the laboratory session
- Relevant Modules:
- Week Twelve: April 3 to April 7: Probability Functions
- Week Thirteen: April 10 to April 14: Mathematical Mappings
- Week Fourteen: April 17 to April 21: Object-Oriented Programming
- Week Fifteen: April 24 to April 28: Mathematical Objects
- Week Sixteen: May 1: Proactive Review
- Final Examination: Examination Code: A, Date: Thursday, May 4, 2023 at 9:00 AM
- Comprehensively covers all course modules
Course Policies¶
Grading¶
The grade that a student receives in this class will be based on the following categories. All of these percentages are approximate and, if the need to do so presents itself, it is possible for the course instructor to change the assigned percentages during the academic semester.
Category | Percentage |
---|---|
Course Participation | 5% |
Midterm Examinations | 10% |
Final Examination | 15% |
Source Code Surveys | 15% |
Programming Projects | 15% |
Engineering Efforts | 40% |
These grading categories have the following definitions:
-
Course Participation: Students are expected to regularly attend and actively participate in all class and laboratory sessions. After either an unexcused absence or a late attendance to a either a class or laboratory session on two separate occasions, a student's course participation grade will be reduced by half a percentage for each additional time they are absent or late in an unexcused fashion. Students who need to miss class or attend class late for an excused reason should communicate their situation to the course instructor as soon as possible. The content that a student commits to their GitHub repositories during the weeks devoted to proactive review are also a component of a student's grade for class participation.
-
Midterm Examinations: The midterms are online cumulative assessments covering all prior material from the class, programming, and laboratory sessions, as outlined on the course schedule. Unless prior arrangements are made with the instructor, all students should use their computer to take this test on the scheduled date and to complete it in the stated location while taking no more than the required amount of time. Each midterm is an executable examination that a student will complete through the use of GitHub, VS Code, and the programming tools installed on their laptops.
-
Final Examination: The final is an online cumulative assessment covering all of the material from the class, programming, and laboratory sessions, as outlined on the review sheet. Unless prior arrangements are made with the course instructor, all students will be expected to use their computer to take this test on the scheduled date and complete the test in the stated period of time.
-
Source Code Surveys: Graded on a checkmark basis and building on material in the textbook and the content covered during that week's in-person classroom sessions, source code surveys have the following goals: (i) help a learner to demonstrate that they can remember learned material by recalling facts, basic concepts, and answers to questions presented in the textbook and on the course web site and (ii) allow a learner to demonstrate an understanding of facts and ideas by translating, interpreting, and stating the main technical ideas presented through the textbook and course web site.
-
Programming Projects: Graded on a checkmark basis and building on material available in the textbook and the content covered during that week's in-person classroom session, the programming projects further equip a learner to solve new problems in the field of discrete structures by applying — in a new way — their knowledge of the both discrete mathematics and rigorous Python programming.
-
Engineering Efforts: These assignments invite students to explore different techniques for rigorously designing, implementing, evaluating, and documenting real-world Python programs. These assignments will invite students to use tools like a text editor, a terminal window, and a modern Python development environment to implement functions that strike the right balance between understandability, generalizability, and specialization. Students will also run experiments to evaluate the implementation of a program as they consider trade-offs in the efficiency and expressiveness of its implementation of a mathematical concept.
Assignment Submission¶
All assignments will have a stated due date shared through GitHub, GitHub Classroom, and Google Calendar. Electronic versions of the engineering efforts, programming projects, and source code surveys must be submitted to the instructor through a student's GitHub repository created by GitHub Classroom. No credit will be awarded for any course work that you submit to the incorrect GitHub repository. Unless special arrangements are made with the instructor, no work will be accepted after the published assignment deadline.
Assignment Evaluation¶
Using a report that the instructor shares with you through your assignment's GitHub repository, you will privately receive a grade for and feedback on each assignment. Your grade will be a function of whether or not you completed correct work that fulfills the project's specification and submitted it by the deadline.
Course Attendance¶
It is mandatory for all students to attend the course sessions. If, due to extenuating circumstances, you will not be able to attend a session, then, whenever possible, please communicate with the instructor at least one day in advance to describe your situation. Students who have any signs of illness should not attend any in-person course sessions.
Class Preparation¶
In order to minimize confusion and maximize learning, students must invest time to prepare for the class discussions, laboratory, and programming sessions. During the class periods, the course instructor will often pose challenging questions that could require group discussion, the creation of a Python program or data table, a vote on a thought-provoking issue, or an in-class presentation. Only those students who have prepared for class by reading the assigned material and reviewing the current course assignments will be able to effectively participate in these class discussions.
Importantly, only prepared students will be able to acquire the knowledge and skills that they need to be successful in this course, subsequent courses, and the field of web development. In order to help students remain organized and to effectively prepare for classes, the course instructor will maintain a class schedule with reading assignments and presentation slides, available at on this site. During the class sessions students will also be required to download, use, and modify web site components and data sets that are made available through means such as the course web site and a GitHub repository.
Seeking Assistance¶
Students who are struggling to understand the knowledge and skills developed in either a class, laboratory, or programming session are encouraged to seek assistance from the course instructor and the student technical leaders. Students should, within the bounds of the Honor Code, ask and answer questions on the Slack workspace for our course; please request assistance from the instructor and student technical leaders first through Slack before sending an email. Students who need the course instructor's assistance must schedule a meeting through his web site and come to the virtual meeting with all of the details needed to discuss their question. Students can find out the office hour schedule student technical leaders by viewing the list of student technical leaders.
Using GitHub and Discord¶
This course will primarily use GitHub and Discord for all course communication, as summarized in the list of community connections. We will use GitHub for the sharing of both source code and course projects and for reporting issues in those materials. We will use two distinct Discord servers for all course discussions. The Proactive Programmers Discord Server provides a way for members of the proactive community to use text and video to chat with each other and will be the main forum for discussing technical content in data abstraction. The Allegheny College Computer Science Discord Server will be the main forum for Department of Computer Science announcements.
Using Email¶
Although we will primarily use GitHub and Discord for class communication, the course instructor will sometimes use email to send announcements about important matters such as changes in the schedule. It is your responsibility to check your email at least once a day and to ensure that you can reliably send and receive emails. This class policy is based on the statement about the use of email that appears in The Compass, the College's student handbook; please see the instructor if you do not have this handbook.
Honor Code¶
The Academic Honor Program that governs the entire academic program at Allegheny College is described in the Allegheny Academic Bulletin. The Honor Program applies to all work that is submitted for academic credit or to meet non-credit requirements for graduation at Allegheny College. This includes all work assigned for this class (e.g., examinations and course assignments). All students who have enrolled in the College will work under the Honor Program. Each student who has matriculated at the College has acknowledged the following pledge:
I hereby recognize and pledge to fulfill my responsibilities, as defined in the Honor Code, and to maintain the integrity of both myself and the College community as a whole.
Effective Collaboration¶
Computer science is an inherently collaborative discipline. People must work together to produce large, complex, and ultimately useful software systems. Because of this, the Department of Computer Science at Allegheny College encourages students to engage in collaboration. However, in the context of individual coursework, through which each student must demonstrate their own knowledge, there are certain forms of collaboration that are and are not acceptable.
-
Acceptable forms of collaboration include:
- Discussing high-level concepts, such as the use cases for
while
loops or the various methods that can add elements to alist
. - Referring someone to a course text book, course slides, example programs, or other resources that contain helpful information or instructions.
- Outlining the high-level steps to solving a problem or implementing a feature, without mentioning specific lines of code that need to be written.
- Discussing high-level concepts, such as the use cases for
-
Unacceptable forms of collaboration include:
- Sharing details about specific lines of code, including showing your source code to someone or looking at someone else's code.
- Copying someone else's source code, technical writing, program commands, or program output, even with some slight modifications.
- Typing source code, technical writing, or commands on someone else’s computer.
The aforementioned forms of communication are unacceptable because they make it difficult for both the course instructor and a learner to assess individual knowledge. Moreover, these unacceptable forms of collaboration can impede your learning or someone else's learning since an individual is less likely to understand source code or technical writing that they do not create by themself. Any student who participates in these unacceptable forms of collaboration, whether they are the one sharing, showing, looking, copying, or typing, are in violation of Allegheny College's Honor Code.
In summary, students should collaborate as long as they do so in acceptable ways. If a student needs assistance beyond what can be gained through acceptable forms of collaboration, they should seek help from the course instructor or a technical leader. If a student submits deliverables (e.g., source code or technical writing) that are nearly identical to the work of others, this will be taken as evidence of violating the Honor Code.
Disability Services¶
The Americans with Disabilities Act (ADA) is a federal anti-discrimination statute that provides comprehensive civil rights protection for persons with disabilities. Among other things, this legislation requires all students with disabilities be guaranteed a learning environment that provides for reasonable accommodation of their disabilities. Students with disabilities who believe they may need accommodations in this class are encouraged to contact Disability Services at 814-332-2898. Disability Services is part of the Learning Commons and is located in Pelletier Library. Please do this as soon as possible to ensure that approved accommodations are implemented in a timely fashion.
Welcome Message¶
Referring to software, Frederick P. Brooks, Jr. wrote in chapter one of The Mythical Man Month, "The magic of myth and legend has come true in our time." Efficient Python programs that correctly use discrete structures to store and manipulate data have the potential to positively influence the lives of many people. Moreover, the design, implementation, evaluation, and documentation of Python-based software are exciting and rewarding activities! At the start of this class, I invite you to pursue, with great enthusiasm and vigor, this adventure in mathematics and Python programming.
Course Schedule¶
Software Operation¶
Technical Question¶
- How do I install and use the industry-standard programming tools that will help me to rigorously explore discrete structures with the Python programming language?
Next Steps¶
- All written content in and tutorials referenced by the list of proactive technical skills.
Making Connections¶
Technical Question¶
- How do I connect mathematical notation and concepts (e.g., mapping, function, number, and set), to the implementation of useful Python programs that declare and call functions and declare variables and manipulate their values?
Next Steps¶
- Read chapters 1 and 2 of Programming and Mathematical Thinking.
- Check out the course slides for a detailed investigation of these chapters!
- Run the Jupyter notebooks in
discrete-structures/making-connections/
with:
Technical Concepts
- Mapping: set of ordered pairs in which no two first elements are the same
- Function: a process that takes input, performs a computation, and produces output
- Variable: a storage location in memory associated with both a value and a type
- Number: a variable that stores numerical value with a minimum, maximum, and type
- Set: an unordered collection of distinct objects
Programming Constructs¶
Technical Question¶
- How do I use iteration and conditional logic in a Python program to perform computational tasks like processing the contents of a file and mathematical tasks like using Newton's method to approximate the square root of a number?
Next Steps¶
- Read chapter 3 of Programming and Mathematical Thinking
- Read chapter 1 and Appendix B of Doing Math with Python
- Check out the course slides for a detailed investigation of these chapters!
- Run the Jupyter notebooks in
discrete-structures/programming-constructs/
with:
Technical Concepts
- Assignment Statement: an operation to store a value in a variable
- Iteration Construct: a structure to support the repeated execution of operations
- Conditional Logic: a construct to support decision making in a program
- Quadratic Root: value(s) of a quadratic function where it intercepts the horizontal axis
- Square Root: mathematical function that is the inverse of the square of a number
Python Functions¶
Technical Question¶
- How do I use non-recursive functions, recursive functions, and lambda expressions to perform mathematical operations such as computing the absolute value of a number and the mean and median of a sequence of numbers?
Next Steps¶
- Read chapter 4 of Programming and Mathematical Thinking
- Read chapter 3 of Doing Math with Python
- Check out the course slides for a detailed investigation of these chapters!
- Run the Jupyter notebooks in
discrete-structures/python-functions/
with:
Technical Concepts
- Python Function: subroutine or procedure that accepts input, performs steps, and produces output
- Recursive Function: special type of Python function that makes a call to itself in its definition
- Lambda Expression: an expression that accepts input, performs steps, and produces output
- Arithmetic Mean: the average of a list of values calculated by summing the values and divide by the list's size
- Median Value: for a list of values sorted in increasing order, the middle value in the list
Data Containers¶
Technical Question¶
- How do I use the mathematical concepts of ordered pairs, n-tuples, and lists to implement efficient Python programs that use functions with a clearly specified behavior to perform tasks like the input and parsing of a comma separated value file?
Next Steps¶
- Read chapter 5 of Programming and Mathematical Thinking
- Read chapter 2 of Doing Math with Python
- Check out the course slides for a detailed investigation of these chapters!
- Run the Jupyter notebooks in
discrete-structures/data-containers/
with:
Technical Concepts
- Ordered Pair: grouping of two elements such that their order is important
- Tuple: immutable ordered sequence that can contain elements of any type
- Delimiter: a symbol that separates data values
- Flat File: file that has no structure other than being divided into lines and fields
- CSV Format: comma-separated value files that use a comma as a delimiter to separate data
Using Monoids¶
Technical Question¶
- How do I use the mathematical concepts of sequences, monoids, and lists to implement efficient Python programs that use functions with a clearly specified behavior to perform tasks like finding a name in a file or computing the arithmetic mean of data values?
Next Steps¶
- Read chapter 6 of Programming and Mathematical Thinking
- Read chapter 3 of Doing Math with Python
- Check out the course slides for a detailed investigation of these chapters!
- Run the Jupyter notebooks in
discrete-structures/using-monoids/
with:
Technical Concepts
- Sequence: a collection of ordered homogeneous elements such a strings and files
- File: a sequence of lines, where each line is itself a sequence of characters
- Concatenation: the process of joining together the contents of two or more variables to form a new variable
- Monoid: abstract discrete structure that describes the behavior of other structures in Python, including a string
- Map Function: function that applies a one-argument function to every element of a sequence
Data Streams¶
Technical Question¶
- How do I use dynamically generated streams of data to implement memory efficient and predictable Python programs?
Next Steps¶
- Read chapter 7 of Programming and Mathematical Thinking
- All previously assigned chapters of Doing Math with Python
- Check out the course slides for a detailed investigation of these chapters!
- Run the Jupyter notebooks in
discrete-structures/data-streams/
with:
Technical Concepts
- Static Sequence: a sequence of values that, at any one time, exists as a complete data structure
- Dynamically-Generated Sequence: a sequence of values that is all present at once and can appear over time
- Generator Function: a function that incrementally yields its contents through an iterator
- Endless Stream: a stream of data that potentially never ends, distinguished from a not-possible infinite stream
- Distributed Processing: Computations on separate computers communicate to solve a large computation
Set Foundations¶
Technical Question¶
- How do I use the mathematical concepts of sets and Boolean logic to design Python programs that are easier to implement and understand?
Next Steps¶
- Read chapter 8 of Programming and Mathematical Thinking
- Read chapter 5 of Doing Math with Python
- Check out the course slides for a detailed investigation of these chapters!
- Run the Jupyter notebooks in
discrete-structures/set-foundations/
with:
Technical Concepts
- Set: an unordered collection of distinct objects
- Empty Set: a set that does not contain any elements in it
- Hashing: using the value of an object to compute its location in a structure
- Subset: a set that contains some, but not all of, the elements in another set
- Infinite Set: set that does not have a fixed number of elements in it
Probability Functions¶
Technical Question¶
- How do I use the implementation of a finite set in
Sympy
to create Python programs that calculate and use probabilities?
Next Steps¶
- Read chapters 4 and 5 of Doing Math with Python
- Read chapter 8 of Programming and Mathematical Thinking
- Check out the course slides for a detailed investigation of these chapters!
- Run the Jupyter notebooks in
discrete-structures/probability-functions/
with:
Technical Concepts
- Power Set: set of all possible subsets of another set
- Experiment: a test to perform to assess a probability of an outcome
- Sample Space: all possible outcomes from an experiment
- Event: set of outcomes that form a subset of the sample space
- Uniform Distribution: distribution of outcomes such that each outcome in the sample is equally likely to occur
Mathematical Mappings¶
Technical Question¶
- How do I use dictionaries, tuples, and lists to correctly implement efficient mathematical functions in Python?
Next Steps¶
- Read chapter 9 of Programming and Mathematical Thinking
- Check out the course slides for a detailed investigation of these chapters!
- Run the Jupyter notebooks in
discrete-structures/mathematical-mappings/
with:
Technical Concepts
- Mathematical Mapping: set of ordered pairs in which no two first elements are the same
- Function Domain: set of values that are the first elements of ordered pairs in a mapping
- Function Range: set of values that are the second elements of ordered pairs in a mapping
- Dictionary: kind of static container that acts like a mapping
- Key-Value Pair: the two-tuples stored in a dictionary that map a key to a value
- Multiset: a dictionary that maps specific values to a count of their occurrence
Object-Oriented Programming¶
Technical Question¶
- How do I use the concept of a relation and the industrially relevant practice of object-oriented programming to correctly implement Python programs that are easy to understand and maintain?
Next Steps¶
- Read chapter 10 (Sections 10.1 and 10.2) and chapter 11 of Programming and Mathematical Thinking
- Check out the course slides for a detailed investigation of these chapters!
- Run the Jupyter notebooks in
discrete-structures/mathematical-mappings/
with:
Technical Concepts
- Object: instance of a class that has both state and behavior
- Method: executable function attached to an instance of a class
- Attribute: variable providing data storage for an instance of a class
- Inheritance: mechanism for building groups of related abstractions that establishes a parent-child relationship
- Information Hiding: principle that the client of a class should only rely on the public methods of the class
Mathematical Objects¶
Technical Question¶
- How do I use the concepts associated with object-oriented programming to create and use objects for the purposes of performing mathematical computations like the moving average?
Next Steps¶
- Read chapter 11 of Programming and Mathematical Thinking
- Check out the course slides for a detailed investigation of these chapters!
- Run the Jupyter notebooks in
discrete-structures/mathematical-mappings/
with:
Technical Concepts
- Number Stream: sequence of numbers that continues without conclusion
- Moving Average: average of fixed amount of vales in a number stream
- Recursively Defined Object: a class that is partly defined in terms of itself
- Tree: a node-based, hierarchical discrete structure with characteristics distinct from a graph
- Root: the distinguished node of a tree from which other nodes originate
Learning Opportunities¶
Interested in learning more about any of the topics on this schedule? If you are, then make sure to connect with members of the proactive community for more learning opportunities. Remember, this course emphasizes building mastery of the course's learning objectives through "learning by doing", as explained in the description of proactive learning. As such, you can best understand the content on this schedule by completing all the source code surveys, programming projects, and engineering efforts!
Source Code Surveys ↵
Data Types¶
Project Goals¶
This assignment invites you to run and observe two Python programs called
compare-variables
and demonstrate-variable-limitations
. Instead of using
the Poetry tool for managing dependencies and
packaging these programs, which the technical
skills advise as a best
practice, these programs are scripts, without any dependencies on other Python
packages, that you can run through the Python interpreter. As you learn a new
way to run a Python program, this project offers you the opportunity to ensure
that you understand how to (i) understand the representation of float-point
variables and (ii) the time and space limitations associated with performing
computations with numbers. Ready to explore some of the limitations of data
variables in Python? Okay, let's get started!
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to add source code and documentation to the
project!
Note
If you are an emerging proactive programmer who is not enrolled in a Computer Science class at Allegheny College, you can still work on this assignment! To get started, you should click the "Use this template" icon in the data-types-starter GitHub repository and create your own version of this project's source code. After creating your GitHub repository, you can follow all of the other steps!
Code Survey¶
If you change into the source
directory of your GitHub repository, you will
see two Python files called compare-variables.py
and
demonstrate-variable-limitations.py
. You can run the compare-variables.py
program by typing python compare-variables.py
in your terminal window. What
output does the program produce? Can you explain why it produces this output?
The key to understanding this segment of source code is to notice that the
conditional logic in lines 1
through 4
use a programmer's decimal
approximation of \(\frac{1}{3}\) while lines 5
through 8
use the fraction
itself. What does this output tell you about the difference between .33333
and (1/3)
in the Python language?
1 2 3 4 5 6 7 8 |
|
The second Python program is called demonstrate-variable-limitations.py
because it uses the exponentiation operator, written as **
, to raise different
numbers to different powers. As shown on line 1
in the following excerpt from
this program, it is feasible to efficiently perform the computation 2**2**8
,
written as \(2^{2^8}\) using mathematical notation. Line 3
also shows that it is
possible to efficiently compute the value of \(2^{2^{10}}\) using the Python
expression 2**2**10
. Although not shown in the following source code segment,
the demonstrate-variable-limitations.py
script also has commented-out source
code that performs the computation 2**2**100
. If you un-comment this source
code and run the program by typing python demonstrate-variable-limitations.py
what
does the output tell you about the challenges of efficiently performing
exponentiation?
1 2 3 4 |
|
Running Checks¶
Since this project does not use Poetry to manage
project dependencies and virtual environments, it does not support the use of
commands like poetry run task test
. However, you can leverage the relevant
instructions in the technical
skills to run the command
gatorgrade --config config/gatorgrade.yml
to check your work. If gatorgrade
shows that all checks pass, you will know that you made progress towards
correctly implementing and writing about this project's two programs.
Note
Did you know that GatorGrade and GatorGrader are open-source Python programs implemented by many proactive programmers? If you finish this source code survey and have extra time, please brainstorm some new features that you think these two tools should have, explain your idea by raising an issue in the relevant project's GitHub repository, and take the first step towards implementing and testing your idea. If the maintainers of these tools accept your new feature then you will have helped to improve the experience of other people who use GatorGrade and GatorGrader!
Project Reflection¶
Once you have finished all of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file. Since
this is a source code survey, you should provide output from running each of the
provided Python programs on your own laptop and then explain how the program's
source code produced that output. A specific goal for this project is to ensure
that you can explain how Python programs should use integer numbers and
exponentiation in an efficient and correct fashion.
Project Assessment¶
Since this project is source code survey, it is aligned with the remembering and understanding levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet the project's specification.
Note
Before you finish all of the required deliverables required by this project is worth pausing to remember that the instructor will give advance feedback to any learner at Allegheny College who requests it through GitHub and Discord at least 24 hours before the project's due date! Seriously, did you catch that? This policy means that you can thoroughly understand the ways to improve your project before its final assessment! To learn more about this opportunity, please read the assessment strategy for this site.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.
Tuple Swapping¶
Project Goals¶
This assignment invites you to run and observe one Python program called
perform-ordered-pair-swap
. Instead of using the
Poetry tool for managing dependencies and
packaging these programs, which the technical
skills advise as a best
practice, this program is a script, without any dependencies on other Python
packages, that you can run through the Python interpreter. As you continue to
practice a different way to run a Python program, this project invites you to
explore how to (i) find and fix defects in a function and (ii) create and use
fixed-size tuples that can contain arbitrary types of data.
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to add source code and documentation to the
project!
Note
If you are an emerging proactive programmer who is not enrolled in a Computer Science class at Allegheny College, you can still work on this assignment! To get started, you should click the "Use this template" icon in the data-types-starter GitHub repository and create your own version of this project's source code. After creating your GitHub repository, you can follow all of the other steps!
Code Survey¶
If you change into the source
directory of your GitHub repository, you will
see a Python program called perform-ordered-pair-swap.py
. Your goal for this
project is to find and fix the defects in the function with the signature def
ordered_pair_swap(pair_one: Tuple[Any, Any], pair_two: Tuple[Any, Any]) ->
Tuple[Tuple[Any, Any], Tuple[Any, Any]]
. When you run the command python
perform-ordered-pair-swap.py
after correcting the program's defects, it should
produce the following output:
Original tuple of ordered pairs: (('A', 1), ('B', 2))
Swapped tuple of ordered pairs: ((2, 'B'), (1, 'A'))
Swapped (again) tuple of ordered pairs: (('A', 1), ('B', 2))
It is worth noting that the ordered_pair_swap
function performs two types of
swapping. It first swaps the values inside of each of the ordered pairs, as
evidenced in the first and second lines of the output, where the first tuple is
input as ('A', 1)
and output as (1, 'A')
. The second type of swap performed
by the function involves outputting the second tuple first and the first tuple
second, which the second output line illustrating with ((2, 'B'), (1, 'A'))
for an input of (('A', 1), ('B', 2))
. The final line of the program output
also illustrates that the tuple swapping process is reversible since the
function can accept as input ((2, 'B'), (1, 'A'))
and produce as output
(('A', 1), ('B', 2))
— which is the original tuple that started this the
tuple swapping process!
Running Checks¶
Since this project does not use Poetry to manage
project dependencies and virtual environments, it does not support the use of
commands like poetry run task test
. However, you can leverage the relevant
instructions in the technical
skills to run the command
gatorgrade --config config/gatorgrade.yml
to check your work. If gatorgrade
shows that all checks pass, you will know that you made progress towards
correctly implementing and writing about this project's program.
Note
Did you know that GatorGrade and GatorGrader are open-source Python programs implemented by many proactive programmers? If you finish this source code survey and have extra time, please brainstorm some new features that you think these two tools should have, explain your idea by raising an issue in the relevant project's GitHub repository, and take the first step towards implementing and testing your idea. If the maintainers of these tools accept your new feature then you will have helped to improve the experience of other people who use GatorGrade and GatorGrader!
Project Reflection¶
Once you have finished all of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file. Since
this is a source code survey, you should provide output from running each of the
provided Python programs on your own laptop and then explain how the program's
source code produced that output. A specific goal for this project is for you to
improve and document the source code of a function that indexes a tuple in order
to swap its contents.
Project Assessment¶
Since this project is source code survey, it is aligned with the remembering and understanding levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet the project's specification.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.
Higher-Order Functions¶
Project Goals¶
This assignment invites you to run and observe two Python programs stored in
files called demonstrate-map-function.py
and demonstrate-reduce-function.py
.
Both of these programs demonstrate the use of higher-order functions that can
accept as input a callable function and then use that function to perform a
computation. Specifically, the demonstrate-map-function.py
illustrates the use
of a map(f, sequence)
function that applies the function f
to a list of data
values called sequence
. The demonstrate-reduce-function.py
shows the use of
a reduce(f, sequence, initial)
function that starts at an initial
value and
then applies a function f
to all of the values in sequence
and returns a
result. As you run these two programs and study their output you will explore an
alternative approach to programming, called functional programming.
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to add source code and documentation to the
project!
Code Survey¶
If you change into the source
directory of your GitHub repository, you will
see a Python program called demonstrate-map-function.py
. Your goal for this
project is to implement both a map
higher-order function and a square
function that can serve as the input to the map
function. When you run the
command python demonstrate-map-function.py
after adding the required source
code to the program, it should produce the following output:
Squaring all of the numbers in the values tuple
(4, 9, 25, 49, 121)
Squaring all of the numbers output by range(10)
(0, 1, 4, 9, 16, 25, 36, 49, 64, 81)
It is worth noting that the demonstrate-map-function.py
should contain the
following source code that calls the map
function to produce the
aforementioned output. Line 1
of this code creates a tuple called values
that contains five numbers and line 2
calls the map
function by providing it
square
and the values
. After you have correctly implemented the map
and
square
functions the two print
statements on lines 3
and 4
will produce
the first two lines of output. As shown in the output, the next source code
segment in demonstrate-map-function.py
performs the same operation while using
range(10)
instead of the specific numbers in the values
tuple.
1 2 3 4 |
|
You should also notice that the source
directory of your GitHub repository
contains a Python program called demonstrate-map-function.py
. Your goal for
this project is to implement a reduce
higher-order function and both a plus
and a multiply
function that perform arithmetic on two input numbers and can
serve as the input to the map
function. When you run the command python
after adding the required source code to the
program, it should produce the following output:
Adding all of the numbers together with a reduce function
15
Multiplying all of the numbers together with a reduce function
120
It is worth noting that the demonstrate-reduce-function.py
should contain the
following source code that calls the reduce
function to produce the
aforementioned output. Line 1
of this code creates a list called numbers
that contains five numbers and line 2
calls the reduce
function by providing
it plus
and the numbers
list. After you have correctly implemented the
reduce
and plus
functions the two print
statements on lines 3
and 4
will produce the first two lines of output. As shown in the output, the next
source code segment in demonstrate-reduce-function.py
performs a similar
computation while calling reduce(multiply, numbers, 1)
instead of
reduce(plus, numbers, 0)
. Why it is sensible to specify that the
initial
parameter for reduce
should be 1
instead of 0
when using the
multiply
function instead of plus
?
1 2 3 4 |
|
As you continue this source code survey, make sure to note that the
function signatures in demonstrate-map-function.py
look like those in
the following list. This list demonstrates that these functions do not
have type annotations. After providing the source code for the square
and map
functions in this file, please determine and add the type
annotations for the formal parameters called value
, f
, and
sequence
. Similarly, there are three functions called plus
,
multiply
, and reduce
in the demonstrate-reduce-function.py
file
that do not have type annotations. You can study the source code of
these functions and the way that they are called in the
demonstrate-reduce-function.py
script to learn more about what type
annotations you should add to the formal parameters called number_one
,
number_two
, f
, sequence
, and initial
. When you add these type
annotations, you should leverage them to enhance your understanding of
the inputs, outputs, and behavior of a map-reduce computation.
- Functions in the
demonstrate-map-function.py
file:def square(value)
def map(f, sequence)
- Functions in the
demonstrate-reduce-function.py
file:def plus(number_one, number_two)
def multiply(number_one, number_two)
def reduce(f, sequence, initial)
Running Checks¶
Since this project does not use Poetry to manage
project dependencies and virtual environments, it does not support the use of
commands like poetry run task test
. However, you can leverage the relevant
instructions in the technical
skills to enter into a Docker
container and run the command gradle grade
to check your work. If gradle
grade
shows that all checks pass, you will know that you made progress towards
correctly implementing and writing about this project's two programs.
Project Reflection¶
Once you have finished all of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file. Since
this is a source code survey, you should provide output from running each of the
provided Python programs on your own laptop and then explain how the program's
source code produced that output. A specific goal for this project is for you to
understand each line of source code needed to implement a simplified version of
the map
and reduce
functions. You should also think carefully about the
steps that you would need to take to implement a distributed and/or parallel
computation that uses map
and reduce
to improve the efficiency of a
program.
Project Assessment¶
Since this project is source code survey, it is aligned with the remembering and understanding levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet the project's specification.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.
Mode Calculation¶
Project Goals¶
This assignment invites you to run and observe one Python program called
perform-mode-calculation
. Instead of using the
Poetry tool for managing dependencies and
packaging these programs, which the technical
skills advise as a best
practice, this program is a script, without any dependencies on other Python
packages, that you can run through the Python interpreter. The main reason that
you can run the perform-mode-calculation
as a script is because it does not
have any external package dependencies, instead only using packages that are a
part of the Python language. As you continue to practice a different way to run
a Python program, this project invites you to explore how to (i) import the
Counter
module from the collections
package, (ii) implement a function
called calculate_mode
that can find at most one mode inside of a list of
numbers, and (iii) call the calculate_mode
function and display the values in
the tuple that it produces.
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to add source code and documentation to the
project!
Note
If you are an emerging proactive programmer who is not enrolled in a Computer Science class at Allegheny College, you can still work on this assignment! To get started, you should click the "Use this template" icon in the mode-calculation-starter GitHub repository and create your own version of this project's source code. After creating your GitHub repository, you can follow all of the other steps!
Code Survey¶
If you change into the source/
directory of your GitHub repository, you
will see a Python program called perform-mode-calculation.py
. Your
goal for this project is to find and fix the defects in the function
with the signature def calculate_mode(numbers: List[int]) -> Tuple[int,
int]:
. Specifically, this function signature indicates that the
calculate_mode
function takes as input a list of integer values and
returns a tuple of two integers (i.e., an ordered pair) where the first
value is the number that is the mode and the second value is the number
of times that the mode appeared. To be clear, the calculate_mode
function should find the mode of a list of numbers, or the number that
appears most frequently in the list. When you run the command python
perform-mode-calculation.py
after correcting the program's defects, it
should produce the following output when it looks for a mode in the
scores = [7, 8, 9, 2, 10, 9, 9, 9]
.
The mode of the list of numbers is 9
The mode of the list of was found 4 times!
It is worth noting that the calculate_mode
function will only work correctly
when it is provided with a list that contains a single value for the mode. If
there are multiple values for the mode (i.e., the list scores = [7, 8, 7, 7, 9,
2, 10, 9, 9, 9]
has both the number 7
and the number 9
as a mode) then it
will not return both of them. How would you need to change the function's
computation and the type of data that it returns in order to ensure that can
return all modes that are evident in the input list? Finally, don't forget that
it is only possible for the program to run correctly if it contains the import
statements that make the classes for the type annotations available! This means
that you need to have both from typing import List
and from typing import
Tuple
at the top of the perform-mode-calculation.py
. Since the source code in
the Doing Math with Python book uses the Counter
module, the
perform-mode-calculation.py
script also needs the statement from collections
import Counter
.
Running Checks¶
Since this project does not use Poetry to manage
project dependencies and virtual environments, it does not support the use of
commands like poetry run task test
. However, you can leverage the relevant
instructions in the technical
skills to enter into a
Docker container and run the command gradle grade
to check your work. If
gradle grade
shows that all checks pass, you will know that you made progress
towards correctly implementing and writing about this project's program. You
are also encouraged to implement your own test cases for the
perform-mode-calculation.py
script to ensure that it is working correctly!
This might involve creating different inputs to the function under test,
calling the calculate_mode
function, and then adding a statement to check
that the function returned the correct ordered pair as its output.
Note
Did you know that GatorGrade and GatorGrader are open-source Python programs implemented by many proactive programmers? If you finish this source code survey and have extra time, please brainstorm some new features that you think these two tools should have, explain your idea by raising an issue in the relevant project's GitHub repository, and take the first step towards implementing and testing your idea. If the maintainers of these tools accept your new feature then you will have helped to improve the experience of other people who use GatorGrade and GatorGrader!
Project Reflection¶
Once you have finished all of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file. Since
this is a source code survey, you should provide output from running each of the
provided Python programs on your own laptop and then explain how the program's
source code produced that output. A specific goal for this project is for you to
improve and document the source code of a function that indexes a tuple in order
to swap its contents.
Project Assessment¶
Since this project is source code survey, it is aligned with the remembering and understanding levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet the project's specification.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.
Using Memoization¶
Project Goals¶
This assignment invites you to run and observe one Python program called
calculate-fibonacci-lru-cache
. Instead of using the
Poetry tool for managing dependencies and
packaging these programs, which the technical
skills advise as a
best practice, this program is a script, without any dependencies on
other Python packages, that you can run through the Python interpreter.
The main reason that you can run the calculate-fibonacci-lru-cache
as
a script is because it does not have any external package dependencies,
instead only using packages that are a part of the Python language. As
you continue to practice a different way to run a Python program, this
project invites you to explore how to (i) implement memoization for a
mathematical computation using a dict
, (ii) how to adopt memoization
using the functools.lru_cache
, and (iii) how to calculate a number in
the Fibonacci sequence using Binet's formula.
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to add source code and documentation to the
project!
Note
If you are an emerging proactive programmer who is not enrolled in a Computer Science class at Allegheny College, you can still work on this assignment! To get started, you should click the "Use this template" icon in the using-memoization-starter GitHub repository and create your own version of this project's source code. After creating your GitHub repository, you can follow all of the other steps!
Code Survey¶
If you change into the source
directory of your GitHub repository, you will
see a Python program called calculate-fibonacci-lru-cache.py
. Your goal for
this project is to add the source code required by the TODO
markers so that
the program produces the output that is given below this paragraph.
Specifically, you will need to add an implementation of the following function:
def fibonacci(number: int) -> int:
. This function should be decorated with the
@functools.lru_cache(maxsize=128)
annotation so that it leverages a
least-recently-used (LRU) cache to store previously computed values, following
the paradigm of memoization and aiming to make the computation faster. If you
run this program with the command python calculate-fibonacci-lru-cache.py
then
it should produce following output. Finally, please observe that the output of
this program illustrates that the LRU cache provided by functools.lru_cache
keeps track of its size and the number of times a value was and was not found
inside of the cache.
Recursive Fibonacci(35) = 9227465
Binet Fibonacci(35) = 9227465
LRU cache information: CacheInfo(hits=33, misses=36, maxsize=128, currsize=36)
Recursive Fibonacci(70) = 190392490709135
Binet Fibonacci(70) = 190392490709135
LRU cache information: CacheInfo(hits=69, misses=71, maxsize=128, currsize=71)
It is worth noting that the calculate-fibonacci-lru-cache
program also
provides a def fibonacci_binet(n: int) -> int
, as described in the following
source code segment, that can calculate the n
-th Fibonacci number with
Binet's
formula. Even
though this function is only accurate --- as implemented in the Python
programming language --- for small values of n
, it is an efficient approach
for ensuring that the other implementations work as expected. Notably, as
explained in the article entitled Fibonacci direct calculation
formula,
the formula that the following equation implements is "mathematically exact,
but in practice [...] subject to floating point error". Can you explain why this
function will not always compute the correct Fibonacci value?
1 2 3 4 5 6 7 |
|
You should also notice that the source
directory contains the Python program
called calculate-fibonacci-dictionary
. You will need to follow the TODO
markers in this file to implement a version of the def fibonacci(number: int)
-> int:
function that creates and uses a dict
to explicitly manage a history
of the inputs to the function and the outputs that resulted from those inputs.
After you are finished implementing this version of the function you should run
the program and confirm that it produces the same output as the one that uses
the LRU cache. With that said, please note that, while this program should
produce the same values for numbers in the Fibonacci sequence, it will not
produce any output concerning the LRU cache since it implements the memoization
directly by creating a dict
and adding to it and then checking it during the
recursive computation. After implementing these two methods, which one do you
prefer? Why?
Running Checks¶
Since this project does not use Poetry to manage
project dependencies and virtual environments, it does not support the use of
commands like poetry run task test
. However, you can leverage the relevant
instructions in the technical
skills to run the command
gatorgrade --config config/gatorgrade.yml
to check your work. If gatorgrade
shows that all checks pass, you will know that you made progress towards
correctly implementing and writing about this project's program.
Note
Did you know that GatorGrade and GatorGrader are open-source Python programs implemented by many proactive programmers? If you finish this source code survey and have extra time, please brainstorm some new features that you think these two tools should have, explain your idea by raising an issue in the relevant project's GitHub repository, and take the first step towards implementing and testing your idea. If the maintainers of these tools accept your new feature then you will have helped to improve the experience of other people who use GatorGrade and GatorGrader!
Project Reflection¶
Once you have finished all of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file. Since
this is a source code survey, you should provide output from running each of the
provided Python programs on your own laptop and then explain how the program's
source code produced that output. A specific goal for this project is for you to
ensure that you can implement and understand two distinct approaches to using
memoization to speed up the computation of a mathematical function. Students who
want to explore this area further are encouraged to experimentally determine how
much slower the Fibonacci computations would be if the LRU cache or the
dict
-based approach were not used to make the functions faster.
Project Assessment¶
Since this project is source code survey, it is aligned with the remembering and understanding levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet the project's specification.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.
Representing Objects¶
Project Goals¶
This assignment invites you to enhance, run, and observe three Python programs
called create-dog-with-class
, create-dog-with-dictionary
, and
create-dog-with-list
. Instead of using the
Poetry tool for managing dependencies and
packaging these programs, which the technical
skills advise as a best
practice, these programs are a script, without any dependencies on other Python
packages, that you can run with the Python interpreter. As you continue to
practice a different way to run a Python program, this project invites you to
explore how to use three different approaches to representing an object in the
Python programming language. After completing this source code survey, you
should understand how to express relationships between variables in three
different ways and be able to articulate the trade-offs associated with each
approach.
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to add source code and documentation to the
project!
Note
If you are an emerging proactive programmer who is not enrolled in a Computer Science class at Allegheny College, you can still work on this assignment! To get started, you should click the "Use this template" icon in the object-oriented-starter GitHub repository and create your own version of this project's source code. After creating your GitHub repository, you can follow all of the other steps!
Code Survey¶
If you change into the source
directory of your GitHub repository, you will
see two Python programs called create-dog-with-dictionary.py
and
create-dog-with-list.py
. Importantly, both of these Python programs should
produce the same output! Your goal for this project is to add the source code
required by the TODO
markers so that the program produces the output that is
given below this paragraph. When you are finished adding the required source
code, both of the aforementioned programs should produce the following output.
With that said, the first line produced by create-dog-with-dictionary
should
be Creating dog objects using a dictionary-based approach!
and the first line
produced by create-dog-with-list.py
should be Creating dog objects using a
list-based approach!
. As you implement both of these approaches to representing
objects, please take time to reflect on the relative strengths and weaknesses of
both ways to store details about a Dog
in the computer's memory.
The dog's name is: Bosco
The dog's age is: 6
The dog's breed is: Havanese
The dog's name is: Faith
The dog's age is: 14
The dog's breed is: Havanese
You will notice that the source
directory also contains a Python program,
called create-dog-with-class.py
, that uses the object-oriented programming
paradigm to represent the state and behavior associated with a Dog
object. As
for the two other programs, you should add all of the Python source code
required by the TODO
markers, ensuring that the program produces the
following output. Two of the methods that you will need to implement in the
Dog
class include def __init__(self, name, age, breed):
and def
__str__(self):
. The first of these methods is the constructor, or the method
responsible for creating a new instance of the Dog
class. The second of
these methods is responsible for creating a textual representation of a Dog
object that you can display in a terminal window or a graphical user
interface. As you implement the Python source code for this project, you
should note the ways in which the object-oriented approach to representing an
object supports the combination of both state and behaviors.
Creating dog objects using a object-oriented approach!
Bosco is a 6 years old Havanese
The dog's name is: Bosco
The dog's age is: 6
The dog's breed is: Havanese
Bosco is a 6 years old Havanese
Hey, Bosco roll over!
Faith is a 14 years old Havanese
The dog's name is: Faith
The dog's age is: 14
The dog's breed is: Havanese
Faith is a 14 years old Havanese
Hey, Faith waive bye-bye!
Running Checks¶
Since this project does not use Poetry to manage
project dependencies and virtual environments, it does not support the use of
commands like poetry run task test
. However, you can leverage the relevant
instructions in the technical
skills to run the command
gatorgrade --config config/gatorgrade.yml
to check your work. If gatorgrade
shows that all checks pass, you will know that you made progress towards
correctly implementing and writing about this project's program.
Note
Did you know that GatorGrade and GatorGrader are open-source Python programs implemented by many proactive programmers? If you finish this source code survey and have extra time, please brainstorm some new features that you think these two tools should have, explain your idea by raising an issue in the relevant project's GitHub repository, and take the first step towards implementing and testing your idea. If the maintainers of these tools accept your new feature then you will have helped to improve the experience of other people who use GatorGrade and GatorGrader!
Project Reflection¶
Once you have finished all of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file. Since
this is a source code survey, you should provide output from running each of the
provided Python programs on your own laptop and then explain how the program's
source code produced that output. A specific goal for this project is for you to
ensure that you can implement and understand multiple approaches to representing
objects in the Python programming language.
Project Assessment¶
Since this project is source code survey, it is aligned with the remembering and understanding levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet the project's specification.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.
Ended: Source Code Surveys
Programming Projects ↵
Computing Averages¶
Project Goals¶
This programming project invites you to combine what you learned about the basics of Python programming to implement a useful program that computes the average of all of the numbers in a file that is provided as input to a program. The program will input the numerical values in a file, iterate through them, and return the average (i.e., arithmetic mean) of all the values. Along with adding documentation to the provided source code, you will create your own Python functions that use both iteration constructs and conditional logic to implement a correct program that passes the test suite and all checks. As you enhance your technical skills, you will program with tools such as VS Code and a terminal window and the Python programming language and the Poetry package manager.
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to add source code and documentation to the
project!
Note
If you are an emerging proactive programmer who is not enrolled in a Computer Science class at Allegheny College, you can still work on this assignment! To get started, you should click the "Use this template" icon in the average-computation-starter GitHub repository and create your own version of this project's source code. After creating your GitHub repository, you can follow all of the other steps!
Expected Output¶
This project invites you to implement a program called average
that performs
arithmetic. The program accepts through its command-line a file that contains
integer values encoded as text. If you run the program with the command poetry
run average --dir input --file numbers.txt
it produces this output:
😃 Computing the average of numbers in a file called input/numbers.txt!
😉 Phew, that was hard work!
✨ The average of the input values is -0.95
Although this example shows the average
program performing its computation
with the numbers.txt
file in the input
directory, it should work in a
general-purpose fashion for any text file that contains integer numbers aligned
in a single row like:
-19
-24
-81
12
16
To learn more about how to run this program, you can type the command poetry
run average --help
to see the following output showing how to use average
:
Usage: average [OPTIONS]
Process a file by computing the average of all the numbers.
Options:
--dir PATH
--file PATH
--install-completion Install completion for the current shell.
--show-completion Show completion for the current shell, to copy it
or customize the installation.
--help Show this message and exit.
Please note that the provided source code does not contain all of the
functionality to produce this output. As explained in the next section, you
should add all of the missing features to ensure that average
produces the
expected output. Once the program is working correctly, it should produce all of
the expected output described in this section.
Note
Don't forget that if you want to run the average
program you must use your
terminal window to first go into the GitHub repository containing this
project and then go into the average
directory that contains the project's
source code. Finally, remember that before running the program you must run
poetry install
to add the dependencies.
Adding Functionality¶
If you study the file average/average/main.py
you will see that it has many
TODO
markers that designate the parts of the program that you need to
implement before average
will produce correct output. If you run the provided
test suite with the command poetry run task test
you will see that it produces
output like the following:
def test_average_computation_five_numbers():
"""Confirm that it is possible to average together five non-zero numbers."""
number_list = """-72
29
61
-42
44"""
average_value = main.compute_average(number_list)
> assert average_value == ((-72 + 29 + 61 + -42 + 44) / 5)
E assert 0 == (((((-72 + 29) + 61) + -42) + 44) / 5)
Note that this test case fails because of the fact that, by default, the
compute_average
function returns 0
instead of the correct arithmetic mean of
the numbers specified in the number_list
variable. You will need to add source
code to the compute_average
function so that it correctly calculates the
average of the input values!
In summary, you should implement the following functions for the average
program:
def compute_average(contents: str) -> float:
def average(dir: Path = typer.Option(None), file: Path = typer.Option(None)) -> None:
It is worth noting that the compute_average
function accepts as input a str
that is a one-number-per-line encoding of the file that contains the integer
numbers. This means that compute_average
will need to iterate through each
line in the file and convert the text-based encoding of the number to an int
.
The compute_average
function should also handle the circumstance in which the
user-provided file (i.e., numbers.txt
) does not have any numbers inside of it!
If there were no numbers in the file, then the function can return -1
to
indicate that it did not compute an average. As you are finishing your
implementation of the compute_average
function, you should also ensure that,
if all of the numbers inside of the file are 0
, then it returns an average of 0
.
Running Checks¶
If you study the source code in the pyproject.toml
file you will see that it
includes the following section that specifies different executable tasks like
lint
. If you are in the average
directory that contains the
pyproject.toml
file and the poetry.lock
file, the tasks in this section
make it easy to run commands like poetry run task lint
to automatically run
all of the linters designed to check the Python source code in your program and
its test suite. You can also use the command poetry run task black
to confirm
that your source code adheres to the industry-standard format defined by the
black
tool. If it does not adhere to the standard then you can run the
command poetry run task fixformat
and it will automatically reformat the
source code.
Along with running tasks like poetry run task lint
, you can leverage the
relevant instructions in the technical
skills to run the command
gatorgrade --config config/gatorgrade.yml
to check your work. If your work
meets the baseline requirements and adheres to the best practices that
proactive programmers adopt you will see that all the checks pass when you run
gatorgrade
. You can study the config/gatorgrade.yml
file in your repository
to learn how the
GatorGrade program runs
GatorGrader
to automatically check your program and technical writing.
If your program has all of the anticipated functionality, you can run the
command poetry run task test
and see that the test suite produces output like
this:
collected 5 items
tests/test_average.py .....
You will know that the compute_average
function correctly returns 0
when all
of the inputs are 0
if the following test case passes:
1 2 3 4 5 6 7 8 9 |
|
Lines 3
through 7
of this test case define the number_list
variable as one
that contains a list of 0
values separated by newlines. The purpose of
number_list
is to represent the string that would arrive from the input file
if a person ran the average
program on the command-line. Line 8
of this test
case calls the compute_average
function with the number_list
as the input
and stores the output in a variable called average_value
. Finally, line 9
confirms that compute_average
calculates the average of the input as 0
.
You will know that the compute_average
function correctly returns -1
when
there is no input to the function if the follow test case passes:
1 2 3 4 5 |
|
On line 3
in the above source code, this test defines number_list
as an
empty string, denoted by ""
. Finally, on line 4
it calls the
compute_average
function with number_list
as its input and on line 5
it
confirms that the computed average_value
is -1
, as required by the
specification of the function under test.
Once all of the test cases pass, you can run the all of the automated checks by
typing poetry run task all
in your terminal and confirming that there are no
errors in the output. If all of the checks pass, then you can run the program
with the command poetry run average --dir input --file numbers.txt
and then
confirm that it produces the expected output, including the average of -0.95
.
Note
Don't forget that when you commit source code or technical writing to your GitHub repository for this project, it will trigger the run of a GitHub Actions workflow. If you are a student at Allegheny College, then running this workflow consumes build minutes for the course's organization! As such, you should only commit to your repository once you have made substantive changes to your project and you are ready to confirm its correctness. Before you commit to your repository, you can still run checks on your own computer by either using Poetry and GatorGrader.
Project Reflection¶
Once you have finished all of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file. For
instance, you should provide the output of the Python program in a fenced code
block, explain the meaning of the Python source code segments that you
implemented and tested, compare and contrast different implementations of the
Python function called compute_average
, and answer all of the other questions
about your experiences in completing this project. One specific goal for this
reflection is to ensure that you understand how to accept as input the textual
representation of a list of numbers, convert that to a list of numerical values,
and then perform an average computation on those values.
Project Assessment¶
Since this is a programming project, it is aligned with the applying and analyzing levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet all aspects of the project's specification.
Note
Before you finish all of the required deliverables required by this project is worth pausing to remember that the instructor will give advance feedback to any learner who requests it through GitHub and Discord at least 24 hours before the project's due date! Seriously, did you catch that? This policy means that you can have a thorough understanding of ways to improve your project before its final assessment! To learn more about this opportunity, please read the assessment strategy for this site.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.
Temperature Conversion¶
Project Goals¶
This programming project invites you to combine what you learned about the basics of Python programming to implement a useful program that converts a temperature value between two different measurement scales, Celsius and Fahrenheit. The program inputs the temperature reading that it should convert and a configuration explaining whether it should convert from Celsius to Fahrenheit or from Fahrenheit to Celsius. Using these inputs the program performs the conversion and outputs it in the terminal. Along with adding documentation to the provided source code, you will create your own Python functions that uses both assignment statements and conditional logic to implement a correct program that passes the test suite and all of the checks. As you enhance your technical skills, you will program with tools such as VS Code and a terminal window and the Python programming language and the Poetry package manager.
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to add source code and documentation to the
project!
Expected Output¶
This project invites you to implement a number comparison program called
converter
. The program accepts through its command-line a file that contains
integer values encoded as text. If you run the program with the command poetry
run converter --from-unit Celsius --to-unit Fahrenheit --temperature 22
it
produces this output:
🧮 Converting from Celsius to Fahrenheit!
22.00 degrees in Celsius is 71.60 degrees in Fahrenheit
Since the program can also convert from Fahrenheit to Celsius, you can also run
it with the command poetry run converter --from-unit Fahrenheit --to-unit
Celsius --temperature 71.6
and see that it produces the following output:
🧮 Converting from Fahrenheit to Celsius!
71.60 degrees in Fahrenheit is 22.00 degrees in Celsius
One way in which you can tell that converter
is working correctly is that,
when given "inverse numbers", the output shows that it converts correctly in
both "directions". For instance, converting 22
degrees Celsius to Fahrenheit
yields 71.6
degrees and converting 71.6
degrees Fahrenheit to Celsius
results in 22
degrees! To learn more about how to run this program, you can
type the command poetry run converter --help
to see the following output
showing how to use converter
:
Usage: converter [OPTIONS]
Convert units.from Fahrenheit to Celsius or from Celsius to
Fahrenheit.
Options:
--from-unit [Celsius|Fahrenheit]
[default: Celsius]
--to-unit [Celsius|Fahrenheit] [default: Fahrenheit]
--temperature FLOAT RANGE [default: 98.6]
--install-completion Install completion for the current
shell.
--show-completion Show completion for the current shell,
to copy it or customize the
installation.
--help Show this message and exit.
Please note that the provided source code does not contain all of the
functionality to produce this output. As explained in the next section, you are
invited to add all of the missing features to ensure that converter
produces
the expected output. Once you finish the program, it should produce all of the
expected output described in this section.
Note
Recall that if you want to run the converter
program you must use your
terminal window to first go into the GitHub repository containing this
project and then go into the converter
directory that contains the
project's source code. Remember that before running the program you must run
poetry install
to add the dependencies!
Adding Functionality¶
If you study the file called converter/converter/main.py
you will see that it
has many TODO
markers that designate the parts of the program that you need to
implement before converter
will produce correct output. Along with adding
requested source code to the main
module, you should implement the following
functions in the convert
module:
def convert_celsius_to_fahrenheit(temperature: float) -> float
def convert_fahrenheit_to_celsius(temperature: float) -> float
def convert_temperature(temperature: float, from_unit: units.TemperatureUnitOfMeasurement, to_unit: units.TemperatureUnitOfMeasurement)
The first two functions in this listing input a float
value that respectively
represents a temperature in Celsius or Fahrenheit and then converts it to a
float
representing a respective temperature in Fahrenheit or Celsius. Finally,
the converted_temperature
function uses source code as in the following
segment to first determine what type of temperature conversion the user
requested and then call the appropriate function. For instance, lines 3
and
4
show that, when the requested temperature conversion is from Celsius to
Fahrenheit, the converted_temperature
function will call the
convert_celsius_to_fahrenheit
function. Alternatively, lines 6
through 7
show that convert_temperature
calls convert_fahrenheit_to_celsius
when a
person requests temperature conversion in the opposite direction.
1 2 3 4 5 6 7 8 |
|
Once you have correctly resolved all of the TODO
markers in converter
, it
should produce the expected output described in the previous section. You can
use the following equations to guide your implementation of the
convert_fahrenheit_to_celsius
and convert_celsius_to_fahrenheit
functions.
Knowing that these equations use \(C\) and \(F\) to respectively denote the
temperature in Celsius and Fahrenheit, you can translate them into Python source
code that correctly performs temperature conversion.
Running Checks¶
If you study the source code in the pyproject.toml
file you will see that it
includes the following section that specifies different executable tasks like
lint
. If you are in the converter
directory that contains the
pyproject.toml
file and the poetry.lock
file, the tasks in this section
make it easy to run commands like poetry run task lint
to automatically run
all of the linters designed to check the Python source code in your program and
its test suite. You can also use the command poetry run task black
to confirm
that your source code adheres to the industry-standard format defined by the
black
tool. If it does not adhere to the standard then you can run the
command poetry run task fixformat
and it will automatically reformat the
source code.
Along with running tasks like poetry run task lint
, you can leverage the
relevant instructions in the technical
skills to run the command
gatorgrade --config config/gatorgrade.yml
to check your work. If your work
meets the baseline requirements and adheres to the best practices that
proactive programmers adopt you will see that all the checks pass when you run
gatorgrade
. You can study the config/gatorgrade.yml
file in your repository
to learn how the
GatorGrade program runs
GatorGrader
to automatically check your program and technical writing.
If your program has all of the anticipated functionality, you can run the
command poetry run task test
and see that the test suite produces output like
this:
tests/test_convert.py ........
============================ 8 passed in 0.02s =============================
The test_convert
test suite contains test cases for all of the functions
mentioned in the previous section. Even if the test cases for
convert_fahrenheit_to_celsius
and convert_celsius_to_fahrenheit
pass as
expected it is possible that those for convert_temperature
make not if the way
in which it calls the specific temperature conversion functions is not correct.
When one or more test cases fail, make sure you check to see which ones are
failing so that you can better know where to start the debugging process! The
following test case shows how to test convert_temperature
when lines 3
and
4
configure convert_temperature
to convert from Celsius to Fahrenheit. After
setting the input temperature
to 0
on line 1
and calling the
convert_temperature
function on line 5
, the test case checks on line 6
that the conversion function produced the temperature value of 32
, failing the
test if that is not the case.
1 2 3 4 5 6 |
|
Note
Don't forget that when you commit source code or technical writing to your GitHub repository for this project, it will trigger the run of a GitHub Actions workflow. If you are a student at Allegheny College, then running this workflow consumes build minutes for the course's organization! As such, you should only commit to your repository once you have made substantive changes to your project and you are ready to confirm its correctness. Before you commit to your repository, you can still run checks on your own computer by either using Poetry and GatorGrader.
Project Reflection¶
Once you have finished all of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file. For
instance, you should provide the output of the Python program in a fenced code
block and explain the meaning of the Python source code segments that you
implemented and tested. Along with answering all the questions about your
experiences with project, you should explain every function call that occurs
when running the program with a command like poetry run converter --from-unit
Fahrenheit --to-unit Celsius --temperature 71.6
.
Project Assessment¶
Since this is a programming project, it is aligned with the applying and analyzing levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet all aspects of the project's specification.
Note
Before you finish all of the required deliverables required by this project is worth pausing to remember that the instructor will give advance feedback to any learner who requests it through GitHub and Discord at least 24 hours before the project's due date! Seriously, did you catch that? This policy means that you can have a thorough understanding of ways to improve your project before its final assessment! To learn more about this opportunity, please read the assessment strategy for this site.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.
Contact Searching¶
Project Goals¶
This programming project invites you to implement a program called
contactsearcher
. This program takes as input a comma separate value (CSV) file
that contains the email address and job description of a person and a string
that describes a specific job. After reading in and parsing the CSV file, the
contactsearcher
program will find the email addresses of all the people who
have a job description that contains the provided description. Along with adding
documentation to the provided source code, you will create your own Python
functions that uses iteration constructs and conditional logic to implement a
correct program that passes the test suite and all of the checks. As you enhance
your technical skills, you
will program with tools such as VS Code and a terminal window and the Python
programming language and the Poetry package manager.
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to add source code and documentation to the
project!
Note
If you are an emerging proactive programmer who is not enrolled in a Computer Science class at Allegheny College, you can still work on this assignment! To get started, you should click the "Use this template" icon in the contact-searching-starter GitHub repository and create your own version of this project's source code. After creating your GitHub repository, you can follow all of the other steps!
Expected Output¶
This project invites you to implement a CSV file parsing and searching program
called contactsearcher
. The program accepts through its command-line interface
the name of a file, in this case input/contacts.txt
, that contains the contact
information and job title descriptions for some people. For instance, here are
the first lines of this file:
tylernelson@gmail.com,Careers adviser
gregory02@medina-mayer.com,"Accountant, chartered management"
jonesmiguel@hotmail.com,Health and safety inspector
rsanchez@yahoo.com,"Surveyor, planning and development"
hillfrank@ward-wood.com,"Scientist, physiological"
aaronhunter@gmail.com,"Surveyor, insurance"
kylebarnes@hotmail.com,Records manager
joe70@yahoo.com,Network engineer
torresjames@white.info,Electrical engineer
shawkins@watson.com,Science writer
bakererin@morales.com,"Programmer, multimedia"
It is worth noting that the input/contacts.txt
file contains synthetic data
that the Faker program automatically
generated. With that said, after you have correctly implemented all of the
required features, running the program with the command poetry run
contactsearcher --job-description "engineer" --contacts-file input/contacts.txt
will produce the following output:
The contacts file contains 100 people in it! Let's get searching!
We are looking for contacts who have a job related to "engineer":
joe70@yahoo.com is a Network engineer
torresjames@white.info is a Electrical engineer
grahamjoel@castillo-gilbert.net is a Engineer, technical sales
gsutton@miller.com is a Engineer, maintenance
gharris@villarreal-snow.com is a Water engineer
williamsondavid@lopez.com is a Automotive engineer
ronald83@yahoo.com is a Maintenance engineer
zmarshall@yahoo.com is a Control and instrumentation engineer
christopher35@yahoo.com is a Civil engineer, consulting
jacquelinedavid@hotmail.com is a Engineer, electronics
espinozadaryl@hill-maddox.com is a Engineering geologist
edwardsjacob@gmail.com is a Chemical engineer
Wow, we found some contacts! Email them to learn about your job!
Notice that the output confirms that there are 100
rows inside of the CSV file
called input/contacts.txt
and that you instructed the program to return all of
the email addresses for people whose job description contains the word
engineer
. For the current version of the CSV file, there are twelve people who
have engineer
in their job description, including edwardsjacob@gmail.com
who
is a Chemical engineer
and joe70@yahoo.com
who is a Network engineer
.
Since the contactsearcher
program should return the contact information for
every person who has the provided job description in their job title, searching
for engin
instead of engineer
should also return details about
edwardsjacob@gmail.com
and joe70@yahoo.com
. To learn more about how to run
this program, you can type the command poetry run contactsearcher --help
to
see the following output showing how to use contactsearcher
:
╭─ Options ─────────────────────────────────────────────────────────────╮
│ * --job-description TEXT [default: None] │
│ [required] │
│ --contacts-file PATH [default: None] │
│ --install-complet… [bash|zsh|fish|pow Install completion │
│ ershell|pwsh] for the specified │
│ shell. │
│ [default: None] │
│ --show-completion [bash|zsh|fish|pow Show completion for │
│ ershell|pwsh] the specified shell, │
│ to copy it or │
│ customize the │
│ installation. │
│ [default: None] │
│ --help Show this message │
│ and exit. │
╰───────────────────────────────────────────────────────────────────────╯
Please note that the provided source code does not contain all of the
functionality needed to produce this output. As explained in the next section,
you are invited to add all of the missing features to ensure that
contactsearcher
produces the expected output. Once you finish the program, it
should produce all of the expected output.
Note
Recall that if you want to run contactsearcher
you must use your terminal
window to first go into the GitHub repository containing this project and
then go into the contactsearcher
directory that contains the project's
source code. Remember that before running the program you must run poetry
install
to add the dependencies!
Adding Functionality¶
If you study the file called contactsearcher/contactsearcher/main.py
you will
see that it has many TODO
markers that designate the parts of the program that
you need to implement before contactsearcher
will produce correct output.
Along with adding requested source code to the main
module, you should
implement the function in the convert
module called
search_for_email_given_job(job_description: str, contacts: str) ->
List[List[str]]
. This function takes as input two str
variables called
job_description
and contacts
, with the first of these containing, for
instance, engineer
, and the second containing all of the contents of the
provided CSV file. The search_for_email_given_job
function should use the
csv
package's reader
function to input the CSV file on a row-by-row basis,
and then check each row to see if its job description contains the contents of
the job_description
variable. If the job description on a specific line has
within it the provided job_description
, then the function should record the
email address and continue processing the remainder of the file.
Running Checks¶
If you study the source code in the pyproject.toml
file you will see that it
includes the following section that specifies different executable tasks like
lint
. If you are in the converter
directory that contains the
pyproject.toml
file and the poetry.lock
file, the tasks in this section
make it easy to run commands like poetry run task lint
to automatically run
all of the linters designed to check the Python source code in your program and
its test suite. You can also use the command poetry run task black
to confirm
that your source code adheres to the industry-standard format defined by the
black
tool. If it does not adhere to the standard then you can run the
command poetry run task fixformat
and it will automatically reformat the
source code.
Along with running tasks like poetry run task lint
, you can leverage the
relevant instructions in the technical
skills to run the command
gatorgrade --config config/gatorgrade.yml
to check your work. If your work
meets the baseline requirements and adheres to the best practices that
proactive programmers adopt you will see that all the checks pass when you run
gatorgrade
. You can study the config/gatorgrade.yml
file in your repository
to learn how the
GatorGrade program runs
GatorGrader
to automatically check your program and technical writing.
If your program has all of the anticipated functionality, you can run the
command poetry run task test
and see that the test suite produces the
following output. As you finish your implementation of the
search_for_email_given_job
function you can use this test suite to confirm
that it is working correctly. If one of the test cases fails, you can use its
output to help you understand what is not yet working in the function that it
tests.
tests/test_search.py .....
============================ 5 passed in 0.02s =============================
Note
Don't forget that when you commit source code or technical writing to your GitHub repository for this project, it will trigger the run of a GitHub Actions workflow. If you are a student at Allegheny College, then running this workflow consumes build minutes for the course's organization! As such, you should only commit to your repository once you have made substantive changes to your project and you are ready to confirm its correctness. Before you commit to your repository, you can still run checks on your own computer by either using Poetry or Docker and GatorGrader.
Project Reflection¶
Once you have finished all of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file. For
instance, you should provide the output of the Python program in a fenced code
block and explain the meaning of the Python source code segments that you
implemented and tested. As you answer the reflection's questions, take
particular care as you explain every computational step that occurs when running
the program with a command like poetry run contactsearcher --job-description
"engineer" --contacts-file input/contacts.txt
.
Project Assessment¶
Since this is a programming project, it is aligned with the applying and analyzing levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet all aspects of the project's specification.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.
Ended: Programming Projects
Engineering Efforts ↵
File Searching¶
Project Goals¶
This engineering effort invites you to combine what you learned about the basics of Python programming to implement a useful program that can search for a word in a file. As you enhance your technical skills, you will program with tools such as VS Code and a terminal window and the Python programming language and the Poetry package manager.
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to add source code and documentation to the
project!
Note
If you are an emerging proactive programmer who is not enrolled in a Computer Science class at Allegheny College, you can still work on this assignment! To get started, you should click the "Use this template" button in the file-search-starter GitHub repository and create your own version of this project's source code. After creating your GitHub repository, you can follow all of the other steps!
Expected Output¶
This project invites you to implement a file searching program called search
.
The search
program takes as input a word (e.g., "proactive") and determines
whether or not it is in the text of a file provided on the input. For instance,
if the file called input/proactive.txt
contains inside of the text on the main
page of this web site, then searching for the word proactive
with the
command poetry run search --word ethical --dir input --file proactive.txt
yields:
😃 Searching through the file called input/proactive.txt!
Was the word "ethical" found in the file input/proactive.txt? Yes
When you search for a word that does not appear inside of the input file with a
command like poetry run search --word conundrum --dir input --file
proactive.txt
then the program will produce the following output:
😃 Searching through the file called input/proactive.txt!
Was the word "conundrum" found in the file input/proactive.txt? No
Once your program is working correctly, you should also try to use it when
specify a file that is not available on your computer! For instance, if you run
it with the command poetry run search --word proactive --dir input --file
notfound.txt
then it will not perform a search and instead produce the
following output:
😃 Searching through the file called input/notfound.txt!
🤷 input/notfound.txt was not a valid file
Note
Don't forget that if you want to run the search
program you must use your
terminal window to first go into the GitHub repository containing this
project and then go into the search
directory that contains the project's
source code. Finally, remember that before running the program you must run
poetry install
to add the dependencies.
Adding Functionality¶
If you study the file search/search/main.py
you will see that it has many
TODO
markers that designate the parts of the program that you need to
implement before search
will produce correct output. If you run the provided
test suite with the command poetry run task test
you will see that it produces
output like the following:
================================== ERRORS ==================================
__________________ ERROR collecting tests/test_search.py ___________________
tests/test_search.py:5: in <module>
from search import main
search/main.py:31: in <module>
???
E NameError: name 'cli' is not defined
========================= short test summary info ==========================
ERROR tests/test_search.py - NameError: name 'cli' is not defined
!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!
============================= 1 error in 0.11s =============================
Alternatively, running the program with a command like poetry run search --word
ethical --dir input --file proactive.txt
will produce the following output:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/gkapfham/.pyenv/versions/3.9.2/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
[...]
@cli.command()
NameError: name 'cli' is not defined
This output suggests that the cli
variable was not correctly declared! After
declaring the cli
variable in the appropriate fashion, following the relevant
instructions in the description of the technical
skills, you should find the
other TODO
markers and correctly resolve them. For instance, you can add this
function to the main.py
file:
1 2 3 4 5 6 7 8 9 |
|
Line 1
of the above source code segment contains the signature for the
confirm_valid_file
function, showing that it takes as input a file
variable
that is of type Path
and returns a bool
to indicate whether or not the file
is valid. If the conditional logic on lines 4
and 6
confirms that the file
variable is both not equal to None
and is, in fact, a file, then the function
returns True
. Otherwise, line 9
of confirm_valid_file
returns False
to
indicate that the provided file
is not valid.
In addition to confirm_valid_file
, you must completely implement these
functions:
def human_readable_boolean(answer: bool) -> str
def word_search(text: str, word: str) -> bool
def word(word: str = typer.Option(None), dir: Path = typer.Option(None), file: Path = typer.Option(None)) -> None
Running Checks¶
If you study the source code in the pyproject.toml
file you will see that it
includes the following section that specifies different executable tasks like
lint
. If you are in the search
directory that contains the pyproject.toml
file and the poetry.lock
file, the tasks in this section make it easy to run
commands like poetry run task lint
to automatically run all of the linters
designed to check the Python source code in your program and its test suite. You
can also use the command poetry run task black
to confirm that your source
code adheres to the industry-standard format defined by the black
tool. If it
does not adhere to the standard then you can run the command poetry run black
search tests
and it will automatically reformat the source code.
Along with running tasks like poetry run task lint
, you can leverage the
relevant instructions in the technical
skills to run the command
gatorgrade --config config/gatorgrade.yml
to check your work. If your work
meets the baseline requirements and adheres to the best practices that
proactive programmers adopt you will see that all the checks pass when you run
gatorgrade
. You can study the config/gatorgrade.yml
file in your repository
to learn how the
GatorGrade program runs
GatorGrader
to automatically check your program and technical writing.
If your program has all of the anticipated functionality, you can run the
command poetry run task test
and see that the test suite produces output like
this:
collected 5 items
tests/test_search.py .....
Note
Don't forget that when you commit source code or technical writing to your
GitHub repository for this project, it will trigger the run of a GitHub
Actions workflow. If you are a student at Allegheny College, then running
this workflow consumes build minutes for the course's organization! As such,
you should only commit to your repository once you have made substantive
changes to your project and you are ready to confirm its correctness. Before
you commit to your repository, you can should run checks on your own computer
by running gatorgrade --config config/gatorgrade.yml
.
Project Reflection¶
Once you have finished both of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file. For
instance, you should provide the output of the Python program in a fenced code
block, explain the meaning of the Python source code segments that you
implemented, and answer all of the other questions about your experiences in
completing this project.
Note
To ensure that you master the technical and professional skills introduced as part of this project you need to participate in deliberate practice that "requires both a clear performance goal and immediate informative feedback".1 After reflecting on the challenges that you faced and identifying areas for improvement, make a list of SMART goals that will enable you to more effectively put a specific technical skill into practice, follow your plan, and continually work to improve.2 You can learn more about how to best reflect on your experiences and improve before starting your next project by reviewing the technical skills that a proactive programmer should master!
Project Assessment¶
Since this project is an engineering effort, it is aligned with the evaluating and creating levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet every aspect of the project's specification.
Note
Before you finish all of the required deliverables required by this project is worth pausing to remember that the instructor will give advance feedback to any learner who requests it through GitHub and Discord at least 24 hours before the project's due date! Seriously, did you catch that? This policy means that you can have a thorough understanding of ways to improve your project before its final assessment! To learn more about this opportunity, please read the assessment strategy for this site.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.
-
See Merriam-Webster for the definition of Teaching Tech Together for more details about how to effectively learn technical skills. What practical steps can you take to best ensure that you can master the technical skills of a proactive programmer? ↩
-
See the article called How to write SMART goals for an overview of how to create SMART goals that are specific, measurable, achievable, relevant, and time-bound. In your view, what are the benefits of ensuring that your goals fit into the SMART paradigm? ↩
Quadratic Roots¶
Project Goals¶
This engineering effort invites you to combine what you learned about
the basics of Python programming and mathematical functions to implement
a useful program that can use an equation to find the roots for a
quadratic equation. The program will have a command-line interface that
accepts as input the values a
, b
, and c
for a quadratic equation
of the form \(f(x) = a \times x^2 + b \times x + c\). As you learn more
about to translate mathematical equations into Python functions and you
continue to enhance your technical
skills, you will
implement and test a complete Python program while using tools such as
the VS Code text editor, a terminal window, and the Poetry package
manager.
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to add source code and documentation to the
project!
Note
If you are an emerging proactive programmer who is not enrolled in a Computer Science class at Allegheny College, you can still work on this assignment! To get started, you should click the "Use this template" button in the quadratic-roots-starter GitHub repository and create your own version of this project's source code. After creating your GitHub repository, you can follow all of the other steps!
Expected Output¶
This project invites you to implement a quadratic root finding program called
rootfinder
. To learn more about the equations for finding the roots of a
quadratic equation, please try out the quadratic formula
calculator.
For instance, input a=1
, b=2
, and c=1
into this calculator and see what
answer it produces. After repairing your program, as explained in the next step
of this assignment, it will also be possible for you to run the provided Python
program by typing poetry run rootfinder --a 1 --b 2 --c 1
in your
terminal window and observe that the programs produces the following output:
⭐ Calculating the roots of a quadratic equation with:
a = 1.0
b = 2.0
c = 1.0
⭐ Finished computing the roots of the equation as:
x_one = -1.0
x_two = -1.0
Does the Python program produce the same output as the quadratic formula
calculator site suggests it should? If it does, then try to run the program with
different inputs by typing poetry run rootfinder --a 1 --b 1 --c 1
. In this
case, your program should produce the following output:
⭐ Calculating the roots of a quadratic equation with:
a = 1.0
b = 1.0
c = 1.0
⭐ Finished computing the roots of the equation as:
x_one = (-0.49999999999999994+0.8660254037844386j)
x_two = (-0.5-0.8660254037844386j)
Is this output the same as what the web-based quadratic formula calculator
produces? Please note that the output of this program includes numbers like
-0.5-0.8660254037844386j
, which means that this is a program that has an
"imaginary" component. If you would like to learn more about "imaginary" numbers
and how you can intuitively and geometrically interpret them, please read the
visual and intuitive guide to imaginary
numbers,
bearing in mind that the referenced article uses the variable i
and Python
programs always use the variable j
to mean the same thing. Finally, please
make sure that you try your program with several additional inputs, always
confirming that it works correctly by using the web-based quadratic formula
calculator.
Note
Remember, if you want to run rootfinder
you must use your terminal to go
into the GitHub repository containing this project and then go into the
rootfinder
directory that contains the project's source code. Finally,
remember that before running the program you must run poetry install
to
add the dependencies. If you run into errors when using a poetry run
command you can often resolve them by deleting the .venv
directry and the
poetry.lock
file and then trying poetry install
again.
Adding Functionality¶
If you study the file rootfinder/rootfinder/main.py
you will see that it has many
TODO
markers that designate the parts of the program that you need to
implement before rootfinder
will produce correct output. If you run the provided
test suite with the command poetry run task test
you will see that it produces
output like the following:
================================= FAILURES =================================
__________________ test_calculate_x_values_non_imaginary ___________________
def test_calculate_x_values_non_imaginary():
"""Check that the calculation of x values works if they are not imaginary."""
a = 1
b = 2
c = 1
> x_one, x_two = rootfind.calculate_quadratic_equation_roots(a, b, c)
E TypeError: cannot unpack non-iterable NoneType object
tests/test_rootfind.py:20: TypeError
Alternatively, running the program with a command like poetry run rootfinder
--a 1 --b 2 --c 1
will not produce any output! This is due to the fact that the
required source code does not yet exist inside of the rootfinder
program. One
function that you need to implement is specified by the following signature.
1 2 3 |
|
This function's type annotations on line 2
suggest that each of its three
inputs are variables of type float
. On line 3
, the notation Union[float,
complex]
means that one of the outputs of calculate_quadratic_equation_roots
can either be a floating-point value of type float
or an imaginary number of
type complex
. The complete annotation of Tuple[Union[float, complex],
Union[float, complex]]
means that the return value of
calculate_quadratic_equation_roots
will be a two-tuple of values, with each
component of the two-tuple being either a float
or a complex
number. This
function should return values for x_one
and x_two
according to the following
equations:
To provide a command-line interface to your program, you should also implement a main function that has the following signature:
1 2 3 4 5 |
|
This function signature shows that rootfinder
accepts as input three
parameters called a
, b
, and c
that respectively have default values of
1
, 2
, and 2
, as seen on lines 2
through 4
. If you run poetry run
rootfinder
if should produce this output:
⭐ Calculating the roots of a quadratic equation with:
a = 1.0
b = 2.0
c = 2.0
⭐ Finished computing the roots of the equation as:
x_one = (-0.9999999999999999+1j)
x_two = (-1-1j)
Running Checks¶
If you study the source code in the pyproject.toml
file you will see that it
includes the following section that specifies different executable tasks like
lint
. If you are in the square
directory that contains the pyproject.toml
file and the poetry.lock
file, the tasks in this section make it easy to run
commands like poetry run task lint
to automatically run all of the linters
designed to check the Python source code in your program and its test suite. You
can also use the command poetry run task black
to confirm that your source
code adheres to the industry-standard format defined by the black
tool. If it
does not adhere to the standard then you can run the command poetry run black
square tests
and it will automatically reformat the source code.
Along with running tasks like poetry run task lint
, you can leverage the
relevant instructions in the technical
skills to run the command
gatorgrade --config config/gatorgrade.yml
to check your work. If your work
meets the baseline requirements and adheres to the best practices that proactive
programmers adopt you will see that all the checks pass when you run
gatorgrade
. You can study the config/gatorgrade.yml
file in your repository
to learn how the
GatorGrade program runs
GatorGrader to
automatically check your program and technical writing. If your program has all
of the anticipated functionality, you can run the command poetry run task test
and see that the test suite produces output like the following. Notice that the
current test suite only has three test cases! If you are looking for an
additional challenge, consider using the quadratic formula
calculator
to guide you as you create new test cases for
calculate_quadratic_equation_roots
that run in
Pytest.
collected 3 items
tests/test_rootfind.py ...
Note
Don't forget that when you commit source code or technical writing to your GitHub repository for this project, it will trigger the run of a GitHub Actions workflow. If you are a student at Allegheny College, then running this workflow consumes build minutes for the course's organization! As such, you should only commit to your repository once you have made substantive changes to your project and you are ready to confirm its correctness. Before you commit to your repository, you can still run checks on your own computer by either using Poetry or Docker and GatorGrader.
Project Reflection¶
Once you have finished both of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file. For
instance, you should provide the output of the Python program in a fenced code
block, explain the meaning of the Python source code segments that you
implemented and used, and answer all of the other questions about your
experiences in completing this project. For instance, your technical writing in
the writing/reflection.md
file should make it clear that you understand the
concept of an "imaginary" number and the notation that the Python programming
language uses to express these numbers.
Note
To ensure that you master the technical and professional skills introduced as part of this project you need to participate in deliberate practice that "requires both a clear performance goal and immediate informative feedback".1 After reflecting on the challenges that you faced and identifying areas for improvement, make a list of SMART goals that will enable you to more effectively put a specific technical skill into practice, follow your plan, and continually work to improve.2 You can learn more about how to best reflect on your experiences and improve before starting your next project by reviewing the technical skills that a proactive programmer should master!
Project Assessment¶
Since this project is an engineering effort, it is aligned with the evaluating and creating levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet every aspect of the project's specification.
Note
Before you finish all of the required deliverables required by this project is worth pausing to remember that the instructor will give advance feedback to any learner who requests it through GitHub and Discord at least 24 hours before the project's due date! Seriously, did you catch that? This policy means that you can have a thorough understanding of ways to improve your project before its final assessment! To learn more about this opportunity, please read the assessment strategy for this site.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.
-
See Merriam-Webster for the definition of Teaching Tech Together for more details about how to effectively learn technical skills. What practical steps can you take to best ensure that you can master the technical skills of a proactive programmer? ↩
-
See the article called How to write SMART goals for an overview of how to create SMART goals that are specific, measurable, achievable, relevant, and time-bound. In your view, what are the benefits of ensuring that your goals fit into the SMART paradigm? ↩
Iterative Exponentiation¶
Project Goals¶
This engineering effort invites you to combine what you learned about the basics
of Python programming to implement a program that can use a for
loop and/or a
while
loop to perform a series of exponentiations. The function that you will
implement will repeatedly perform an exponentiation and then save the result of
the computation in the list. Ultimately, the output of the program should
confirm that it is possible to use either a for
loop or a while
loop to
produce the same program output! As you learn more about how to translate
mathematical equations into Python functions and you continue to enhance your
technical skills, you will
implement and test a complete Python program while using tools such as the VS
Code text editor, a terminal window, and the Poetry package manager.
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to add source code and documentation to the
project!
Note
If you are an emerging proactive programmer who is not enrolled in a Computer Science class at Allegheny College, you can still work on this assignment! To get started, you should click the "Use this template" button in the iterative-exponentiation-starter GitHub repository and create your own version of this project's source code. After creating your GitHub repository, you can follow all of the other steps!
Expected Output¶
This project invites you to implement a program called iterator
. The program
has two flags called --forloop
and --whileloop
that control the type of
iteration construct with which the program performs iterative exponentiation. To
best understand the program's behavior it is nice to observe how it operates
when given different command-line arguments. For instance, the command poetry
run iterator --forloop --whileloop --minimum 0 --maximum 2
produces the
following output. Can you see the pattern? Please note that the use of both the
flags --forloop
and --whileloop
means that the program will iteratively
compute the powers of two with both a for
and while
loop.
Calculating the powers of 2 from 0 to 2 with iteration:
Should I use a for loop? Yes
Should I use a while loop? Yes
Here is the output with the for loop.
2**0 = 1
2**1 = 2
Here is the output with the while loop.
2**0 = 1
2**1 = 2
Wow, all of that iteration was exhausting! 😂
It is important to note that the Python program can also produce the output of
the powers of two using a single type of iteration construct. For instance, the
command poetry run iterator --forloop --minimum 0 --maximum 5
produces
the following output demonstrating that the program only ran a for
loop. As in
the previous output example, this output shows that the program uses the **
operator to raise 2
to the power of a number such as 0
, 1
, and 2
. Both
of these output examples also show that the program should contain several lines
of diagnostic output that make it clear how it interpreted the command-line
arguments before it starting to perform iterative exponentiation.
Calculating the powers of 2 from 0 to 5 with iteration:
Should I use a for loop? Yes
Should I use a while loop? No
Here is the output with the for loop.
2**0 = 1
2**1 = 2
2**2 = 4
2**3 = 8
2**4 = 16
Wow, all of that iteration was exhausting! 😂
While all of the prior examples show that the iterator
works when
you use 0
as the value for the --minimum
, it is also important to
point out that it should work when you increase the value for this
parameter. For instance, when you run poetry run iterator
--forloop --minimum 2 --maximum 10
it should produce the following
output. Note that this output shows that the first exponentiation that
the iterator
performs is 2**2 = 4
instead of starting with 2**0 =
1
as was the case in the previous runs.
Calculating the powers of 2 from 2 to 10 with iteration:
Should I use a for loop? Yes
Should I use a while loop? No
Here is the output with the for loop.
2**2 = 4
2**3 = 8
2**4 = 16
2**5 = 32
2**6 = 64
2**7 = 128
2**8 = 256
2**9 = 512
Wow, all of that iteration was exhausting! 😂
Note
Remember, if you want to run iterator
you must use your terminal to go
into the GitHub repository containing this project and then go into the
iterator
directory that contains the project's source code. Finally,
remember that before running the program you must run poetry install
to
add the dependencies. If you run into errors when using a poetry run
command you can often resolve them by deleting the .venv
directry and the
poetry.lock
file and then trying poetry install
again.
Adding Functionality¶
If you study the file iterator/iterator/main.py
you will see that it has many
TODO
markers that designate the parts of the program that you need to
implement before iterator
will produce the correct output. If you run the
program before adding all of the source code required by the TODO
markers then
iterator
will neither produce the correct output or pass the test suite.
Ultimately, you are invited to add the required functionality to the functions
that have the following signatures. It is important to note that you
should not change the signature of these functions in your own
implementation unless you receive prior approval from the course
instructor.
- Functions in the
display
module:def convert_bool_to_answer(argument: bool)
def display_list(values: List, indent="")
- Functions in the
iterate
module:def calculate_powers_of_two_for_loop(minimum: int, maximum: int)
def calculate_powers_of_two_while_loop(minimum: int, maximum: int)
When you are finished implementing both of the iterative approaches, please take time to evaluate each of them, comparing and contrasting their syntactic structure. Which one do you think is easier to understand? Why? Can you develop any good rules of thumb that suggest when it is better to use one type of loop over the other loop type?
Finally, the following source code segment shows how the main
module
should implement the Python source code that calls the
calculate_powers_of_two_for_loop
and
calculate_powers_of_two_while_loop
functions. Lines 1
and 7
of
this source code segment ensure that the correct function in the
iterate
module is called. Next, lines 2
and 3
and 8
and 9
produce the correct labels that will appear in the console output.
Finally, lines 4
and 10
call the correct iteration function
depending on the command-line arguments specified by the person running
the program. Once either the calculate_powers_of_two_for_loop
or
calculate_powers_of_two_while_loop
function returns a list of values,
the display
function will show the contents of that list with the
amount of indentation specified in the string constant.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Note
Before you start to implement the source code required by this project is worth pausing to remember that the instructor will give advance feedback to any learner who requests it through GitHub and Discord at least 24 hours before the project's due date! Seriously, did you catch that? This policy means that you can have a thorough understanding of ways to improve your project before its final assessment! To learn more about this opportunity, please read the assessment strategy for this site.
Running Checks¶
As you continue to add and confirm the correctness of iterator
's
functionality, you should study the source code in the pyproject.toml
file.
This file contains the specification of several tasks that will help you to
easily run checks on your Python source code. Now, you can run commands like
poetry run task lint
to automatically run all of the linters designed to check
the Python source code in your program and its test suite. You can also use the
command poetry run task black
to confirm that your source code adheres to the
industry-standard format defined by the black
tool. If it does not adhere to
the standard then you can run the command poetry run fixformat
and it will
automatically reformat the source code. By following a
tutorial,
you can configure VS Code to use the black
tool to automatically reformat the
source code when you save a file.
Along with running tasks like poetry run task lint
, you can leverage the
relevant instructions in the technical
skills to run the command
gatorgrade --config config/gatorgrade.yml
to check your work. If your work
meets the baseline requirements and adheres to the best practices that
proactive programmers adopt you will see that all the checks pass when you run
gatorgrade
. You can study the config/gatorgrade.yml
file in your repository
to learn how the
GatorGrade program runs
GatorGrader
to automatically check your program and technical writing.
Note
Don't forget that when you commit source code or technical writing to your
GitHub repository for this project, it will trigger the run of a GitHub
Actions workflow. If you are a student at Allegheny College, then running
this workflow consumes build minutes for the course's organization! As such,
you should only commit to your repository once you have made substantive
changes to your project and you are ready to confirm its correctness. Before
you commit to your repository, you can should run checks on your own computer
by running gatorgrade --config config/gatorgrade.yml
.
Project Reflection¶
Once you have finished both of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file. For
instance, you should provide the output of the Python program in a fenced code
block, explain the meaning of the Python source code segments that you
implemented and used, and answer all of the other questions about your
experiences in completing this project.
Project Assessment¶
Since this project is an engineering effort, it is aligned with the evaluating and creating levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet every aspect of the project's specification.
Note
Before you finish all of the required deliverables required by this project is worth pausing to remember that the instructor will give advance feedback to any learner who requests it through GitHub and Discord at least 24 hours before the project's due date! Seriously, did you catch that? This policy means that you can have a thorough understanding of ways to improve your project before its final assessment! To learn more about this opportunity, please read the assessment strategy for this site.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.
Data Summarization¶
Project Goals¶
This engineering effort invites you to combine what you learned about the basics of Python programming and data analysis to implement a useful program that can summarize a list of floating-point data values stored in a file. However, the first step towards summarizing the data correctly requires the program to transform the input data values from a text-based format to a numerical representation. Along with learning more about how to implement data transformation and summarization routines you will also explore the basics of writing your own test cases. As you enhance your technical skills, you will continue to program with tools such as VS Code and a terminal window and both the Python programming language and the Poetry package manager.
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to add source code and documentation to the
project!
Note
If you are an emerging proactive programmer who is not enrolled in a Computer Science class at Allegheny College, you can still work on this assignment! To get started, you should click the "Use this template" button in the data-summarization-starter GitHub repository and create your own version of this project's source code. After creating your GitHub repository, you can follow all of the other steps!
Expected Output¶
This project invites you to implement a data summarization program called
datasummarizer
. The datasummarizer
program takes as input a file of floating
point values and computes their arithmetic mean. Here is an excerpt from the
input/data.txt
file that contains the floating-point values that the
datasummarizer
must summarize:
2.5169521900e+0
1.8703141360e+0
-3.4505452520e-2
2.3580068020e+0
1.5516879500e+0
As this example indicates, these numbers are floating-point values. Can you
explain why these floating point numbers are written as, for instance,
2.5169521900e+0
? After you have studied and understood the contents of this
file, you are ready to install the project's dependencies with the command
poetry install
and then run it with the command poetry run datasummarizer
--data-file input/data.txt
. Specifically, you will know that your
datasummarizer
works correctly when it outputs the computed mean as
0.9919614640914002
. If you did not get this answer, then please confirm the
correctness of your functions for data transformation and summarization.
🔬 The data file contains 100 data values in it! Let's get summarizing!
🧮 The computed mean is 0.9919614640914002!
Note
Don't forget that if you want to run the datasummarizer
you must use your
terminal to first go into the GitHub repository containing this project and
then go into the datasummarizer
directory that contains the project's
code. Finally, remember that before running the program you must run poetry
install
to add the dependencies.
Adding Functionality¶
If you study the file datasummarizer/datasummarizer/main.py
you will see that
it has many TODO
markers that designate the parts of the program that you need
to implement before datasummarizer
will produce correct output. If you run the
provided test suite with the command poetry run task test
or you try to run
the program with the command poetry run datasummarizer --data-file
input/data.txt
you will see an error message in your terminal window. This is
due to the fact that there are key parts of this program that are missing! In
addition to implementing the program's main functions you also need to correctly
import
the correct modules and objects, like typer
.
Since the datasummarizer
program takes as input textual values from an input
file, you will need to implement a data transformation function that can take as
input a string that contains a numerical value on each line and returns a list
of floating-point values suitable for input into a mathematical computation. For
your reference, here is the signature of the transform_string_to_number_list
function:
def transform_string_to_number_list(data_text: str) -> List[float]
You program also needs to contain a data summarization function that can take as
input a list of floating-point values and then return a single floating-point
value that corresponds to the arithmetic mean of the values in the list. As you
are implementing this function, please ensure that your function can handle
without crashing an empty list of numerical values, returning a "not a number"
(i.e., NaN
) designator in this situation. Here is the signature of the
compute_mean
function that you must implement:
def compute_mean(numbers: List[float]) -> float
In summary, you must follow all of the instructions next to the TODO
markers
in the provided source code to implement a program that can correctly compute
the arithmetic mean of the provided data values in the
datasummarizer/input/data.txt
file. In addition to ensuring that your program
is adequately documented, has the correct industry-standard format, and adheres
to the industry best practices Python programming, you must implement functions
that pass a provided Pytest test suite.
If you look in the files called test_transform.py
and test_summarize.py
you
will find the test suites for the transform
and summarize
modules. As you
complete your implementation of datasummarizer
you should run these tests, as
explained in the next subsection, to confirm that your program's functions are
working correctly. Ultimately, it is important for both your program to produce
the correct output and the test suite to pass!
Note
When you are adding functionality to the datasummarizer
program, make sure
that you work in an incremental fashion, adding a small feature to the
system and then confirming that it works correctly through linting, testing,
and running the program. Once you have added this feature and confirmed that
it works correctly, you should commit your source code to your GitHub
repository and confirm that you have improved the build status of your
project. As you are committing your source code, please pay careful
attention to the commit message that you write! Specifically, you should
make sure that your commit message features a sentence with an active verb
and a clear description of the way in which you changed the source code. You
can read the article How to Write a Git Commit
Message by Chris Beams to
learn some suggestions for ways to improve the quality of your Git commit
messages.
Running Checks¶
As you continue to add and confirm the correctness of datasummarizer
's
functionality, you should study the source code in the pyproject.toml
file.
This file contains the specification of several tasks that will help you to
easily run checks on your Python source code. Now, you can run commands like
poetry run task lint
to automatically run all of the linters designed to check
the Python source code in your program and its test suite. You can also use the
command poetry run task black
to confirm that your source code adheres to the
industry-standard format defined by the black
tool. If it does not adhere to
the standard then you can run the command poetry run fixformat
and it will
automatically reformat the source code. By following a
tutorial,
you can configure VS Code to use the black
tool to automatically reformat the
source code when you save a file.
Along with running tasks like poetry run task lint
, you can leverage the
relevant instructions in the technical
skills to run the command
gatorgrade --config config/gatorgrade.yml
to check your work. If your work
meets the baseline requirements and adheres to the best practices that
proactive programmers adopt you will see that all the checks pass when you run
gatorgrade
. You can study the config/gatorgrade.yml
file in your repository
to learn how the
GatorGrade program runs
GatorGrader
to automatically check your program and technical writing. If your program has
all of the anticipated functionality, you can run the command poetry run task
test
and see that the test suite produces output like the following. It is
important to note that datasummarizer
comes with two test suites, both of
which should pass so as to establish a confidence in the correctness of the
program.
collected 6 items
tests/test_summarize.py ....
tests/test_transform.py ..
Note
Don't forget that when you commit source code or technical writing to your
GitHub repository for this project, it will trigger the run of a GitHub
Actions workflow. If you are a student at Allegheny College, then running
this workflow consumes build minutes for the course's organization! As such,
you should only commit to your repository once you have made substantive
changes to your project and you are ready to confirm its correctness. Before
you commit to your repository, you can should run checks on your own computer
by running gatorgrade --config config/gatorgrade.yml
.
Project Reflection¶
Once you have finished both of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file. For
instance, you should provide the output of the Python program in a fenced code
block, explain the meaning of the Python source code segments that you
implemented, and answer all of the other questions about your experiences in
completing this project. The reflection's objective is to invite you to explain
the Python functions for data summarization and transformation.
Project Assessment¶
Since this project is an engineering effort, it is aligned with the evaluating and creating levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet every aspect of the project's specification.
Note
Before you finish all of the required deliverables required by this project is worth pausing to remember that the instructor will give advance feedback to any learner who requests it through GitHub and Discord at least 24 hours before the project's due date! Seriously, did you catch that? This policy means that you can have a thorough understanding of ways to improve your project before its final assessment! To learn more about this opportunity, please read the assessment strategy for this site.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.
Data Analysis¶
Project Goals¶
This engineering effort invites you to extend your knowledge about the basics of
data analysis to implement a program that can statistically analyze a data set
of real-world population records. After you finish the dataanalysis
program it
will compute the summary statistics (e.g., mean, median, and standard deviation)
of population data from from 1970 until 2019. As you enhance your technical
skills, you will continue to
program with tools such as VS Code and both the Python programming language and
the Poetry package manager. Ultimately, your goal for this project is to create
a program that can efficiently process real-world data about human population
size.
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to add source code and documentation to the
project!
Note
If you are an emerging proactive programmer who is not enrolled in a Computer Science class at Allegheny College, you can still work on this assignment! To get started, you should click the "Use this template" button in the data-analysis-starter GitHub repository and create your own version of this project's source code. After creating your GitHub repository, you can follow all of the other steps!
Expected Output¶
This project invites you to implement a data summarization program called
dataanalysis
. The dataanalysis
program takes as input a file of floating
point values and computes summary statistics about the numbers. Before you
continue to work on this assignment, please make sure that you understand the
meaning of the data in this file. To accomplish this task, you should examine
the discussion of this data set, including its visualization from 1970 until
2019, from the Residential Population in Crawford County,
PA from the Federal Reserve
Bank of St. Louis. The main goal for this program
is that it should summarize the population data for Crawford County, the county
in which Allegheny College is located. Here is an excerpt from the
input/data.txt
file that contains the real-world population data values that
the dataanalysis
program must summarize:
1970-01-01,81.342
1971-01-01,83.300
1972-01-01,84.700
1973-01-01,85.500
1974-01-01,86.100
1975-01-01,87.000
1976-01-01,87.600
1977-01-01,87.600
1978-01-01,88.000
1979-01-01,88.100
1980-01-01,88.869
As this example indicates, the numbers in this file are either strings, that
should be interpreted as a date, or a floating-point value, that is a recording
of a population estimate of people living in Crawford County. After you have
studied and understood the structure of this file's contents, you are ready to
install the project's dependencies with the command poetry install
and then
run it with the command poetry run dataanalysis --data-file input/data.txt
.
After you running the program you can use its output and the data visualization
available from the Federal Reserve Bank of St. Louis to better understand the
population trends for Crawford County. Finally, it is worth noting that the
numerical output from the dataanalysis
program contains four properly indented
floating-point values that are always rounded to two decimal places.
📦 The data file contains 50 data values in it!
🚀 Let's do some sophisticated data analysis!
🧮 Here are the results of the data analysis:
The computed mean is 87.80!
The computed median is 88.05!
The computed variance is 3.69!
The computed standard deviation is 1.92!
💡 What does this tell you about the population of this city?
Note
Don't forget that if you want to run the dataanalysis
you must use your
terminal to first go into the GitHub repository containing this project and
then go into the dataanalysis
directory that contains the project's code.
Finally, remember that before running the program you must run poetry
install
to add the dependencies.
Adding Functionality¶
If you study the file dataanalysis/dataanalysis/main.py
you will see that it
has many TODO
markers that designate the parts of the program that you need to
implement before dataanalysis
will produce the correct output. If you run the
provided test suite with the command poetry run task test
or you try to run
the program with the command poetry run dataanalysis --data-file
input/data.txt
you will see an error message in your terminal window. This is
due to the fact that there are key parts of this program that are missing! In
addition to implementing the program's main
function you also need to
correctly import
the correct modules and objects, like typer
. Along with
adding command-line features to the main
function in the main
module, you
need to provide an implementation of the following functions in other provided
Python files:
def compute_mean(numbers: List[float]) -> float
def compute_median(numbers: List[float]) -> float
def compute_difference(numbers: List[float]) -> List[float]
def compute_variance(numbers: List[float]) -> float
def compute_standard_deviation(numbers: List[float]) -> float
It is worth noting that, when appropriate, one of the aforementioned functions
can call another function. For instance, the compute_standard_deviation
can
call the compute_variance
, thereby reusing its code and avoiding unnecessary
code duplication. In summary, you must follow all of the instructions next to
the TODO
markers in the provided source code to implement a program that can
correctly compute the arithmetic mean of the provided data values in the
dataanalysis/input/data.txt
file. In addition to ensuring that your program is
adequately documented, has the correct industry-standard format, and adheres to
the industry best practices Python programming, you must implement functions
that pass a provided Pytest test suite.
If you look in the files called test_transform.py
and test_summarize.py
you
will find the test suites for the transform
and summarize
modules. As you
complete your implementation of dataanalysis
you should repeatedly run these
tests, as explained in the next subsection, to confirm that your program's
functions are working correctly. Your program should both produce the correct
output and the pass the test suite!
Running Checks¶
As you continue to add and confirm the correctness of datasummarizer
's
functionality, you should study the source code in the pyproject.toml
file.
This file contains the specification of several tasks that will help you to
easily run checks on your Python source code. Now, you can run commands like
poetry run task lint
to automatically run all of the linters designed to check
the Python source code in your program and its test suite. You can also use the
command poetry run task black
to confirm that your source code adheres to the
industry-standard format defined by the black
tool. If it does not adhere to
the standard then you can run the command poetry run fixformat
and it will
automatically reformat the source code. By following a
tutorial,
you can configure VS Code to use the black
tool to automatically reformat the
source code when you save a file.
Along with running tasks like poetry run task lint
, you can leverage the
relevant instructions in the technical
skills to run the command
gatorgrade --config config/gatorgrade.yml
to check your work. If your work
meets the baseline requirements and adheres to the best practices that
proactive programmers adopt you will see that all the checks pass when you run
gatorgrade
. You can study the config/gatorgrade.yml
file in your repository
to learn how the
GatorGrade program runs
GatorGrader
to automatically check your program and technical writing. If your program has
all of the anticipated functionality, you can run the command poetry run task
test
and see that the test suite produces output like the following. It is
important to note that dataanalysis
comes with two test suites, both of
which should pass so as to establish a confidence in the correctness of the
program.
collected 13 items
tests/test_summarize.py ...........
tests/test_transform.py ..
Note
When you are adding functionality to the dataanalysis
program, make sure
that you work in an incremental fashion, adding a small feature to the
system and then confirming that it works correctly through linting, testing,
and running the program. Once you have added this feature and confirmed that
it works correctly, you should commit your source code to your GitHub
repository and confirm that you have improved the build status of your
project. As you are committing your source code, please pay careful
attention to the commit message that you write! Specifically, you should
make sure that your commit message features a sentence with an active verb
and a clear description of the way in which you changed the source code. You
can read the article How to Write a Git Commit
Message by Chris Beams to
learn some suggestions for ways to improve the quality of your Git commit
messages.
Project Reflection¶
Once you have finished both of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file. For
instance, you should provide the output of the Python program in a fenced code
block, explain the meaning of the Python source code segments that you
implemented, and answer all of the other questions about your experiences in
completing this project. The reflection's objective is to invite you to explain
the Python functions for data summarization and transformation. As part of this
project's reflection you should also consider what technical skills taught in
the field of computer science will continue to be the most relevant in the
future.
Project Assessment¶
Since this project is an engineering effort, it is aligned with the evaluating and creating levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet every aspect of the project's specification.
Note
Before you finish all of the required deliverables required by this project is worth pausing to remember that the instructor will give advance feedback to any learner who requests it through GitHub and Discord at least 24 hours before the project's due date! Seriously, did you catch that? This policy means that you can have a thorough understanding of ways to improve your project before its final assessment! To learn more about this opportunity, please read the assessment strategy for this site.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.
List Uniquification¶
Project Goals¶
This engineering effort invites you to investigate how to use various discrete
structures, such as the dictionary and the set, to extract the unique values
contained inside of a list of strings. In addition to implementing and testing
the functions that perform list uniquification, you will produce the majority of
the functions for the program's command-line interface and input processing. You
will also implement functions that calculate the reduction in size and the
percent reduction in size for a list of strings with an unknown amount of
redundancy. To experimentally assess the efficiency of the datauniquifier
program that you implement, this project also invites you to conduct an
experiment to study, for instance, which uniquification process is best at
reducing a list's size.
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to add source code and documentation to the
project!
Note
If you are an emerging proactive programmer who is not enrolled in a Computer Science class at Allegheny College, you can still work on this assignment! To get started, you should click the "Use this template" button in the list-uniquification-starter GitHub repository and create your own version of this project's source code. After creating your GitHub repository, you can follow all of the other steps!
Expected Output¶
To get started on this engineering effort, please make sure that you read the blog post entitled Fastest Way to Uniquify a List in Python. As part of this assignment, you are going to implement at least three ways to remove the duplicate values from one of the columns in a large input file that contains automatically generated data. Here is a sample of the data that you input into the program that you will implement as part of this assignment:
dana74@mahoney-perez.com,"Administrator, charities/voluntary organisations"
nathanjohnson@davila.net,Software engineer
pbush@gmail.com,"Journalist, newspaper"
timothy75@chang.com,Osteopath
gsparks@yahoo.com,"Psychologist, clinical"
daniel39@gmail.com,Logistics and distribution manager
jason85@ward.com,Logistics and distribution manager
jacobwalton@hotmail.com,Television camera operator
markmcgee@hernandez-roberts.com,IT sales professional
shannon35@allen.com,Ecologist
When the program accepts this type of input it will also accept a specific
column for which it should eliminate duplicates through the process of
uniquification. For instance, when the program is run with the command poetry
run datauniquifier --approach listcomprehension --column 1 --data-file
input/data.txt
then it will remove all of the duplicates from column 1
in
the data file that stores the job descriptions of specific individuals.
Alternatively, if the program was run with the command poetry run
datauniquifier --approach listcomprehension --column 0 --data-file
input/data.txt
then it will remove all of the duplicates from column 0
in
the data file that stores the email addresses of specific individuals. If we run
the first of these two previous commands then the program will produce output
like this:
The chosen approach to uniquify the file is: listcomprehension
The data file that contains the input is: input/data.txt
The data file contains 50000 data values in it!
🚀 Let's do some uniquification!
🔍 So, was this an efficient approach to uniquifying the data?
The function 'unique_listcomprehension' took: 0.0063 sec
Estimated overall memory according to the operating system:
37.921875 megabytes
🔍 So, did this remove a lot of duplicate data?
The number of values removed from the data: 1155
The percent reduction due to uniquification: 2.31%
Note
Don't forget that if you want to run the datauniqifier
you must use your
terminal to first go into the GitHub repository containing this project and
then go into the datauniqifier
directory that contains the project's code.
Finally, remember that before running the program you must run poetry
install
to add the dependencies.
Adding Functionality¶
One of your tasks for this project is to address all of the TODO
markers in
the analyze
, extract
, and main
modules of the datauniqifier
program.
After you have completed all of the TODO
markers inside of the provided Python
source code, you should execute the program in a variety of configurations so as
to determine the influence that the size of the input data set, the procedure
chosen for performing uniquification, and the type of data that is input into
the uniquification procedure has on the memory and time efficiency of the
process and the amount of reduction achieved by a specific configuration.
To automatically generate data sets of different sizes, you can use the CSV
Faker tool that relies on the Faker
Package package with a command like csvfaker
--rows 50000 email job > data.txt
. Note that this command will create a data
file called data.txt
that contains two columns, the first for an email
and
the second for a job
. It is also important to note that this command will
generate a data set that contains a total of 50,000 individual records of data.
Please bear in mind that running the csvfaker
program in this fashion may,
depending on the performance characteristics of your laptop, require a long time
to run. Using the aforementioned approach for running the csvfaker
program you
should generate different data files and then use them as the input to the
datauniquifier
program. While everyone learning to be a proactive programmer
is encouraged to use the csvfaker
tool to generate their own data sets, you
can complete this project's required tasks by using the provided data.txt
file
in the input
directory.
Along with varying the size of the data, your experiments should also consider
how the removal of redundant data values varies depending on the type of the
data input into your tool. You can do this by running the program with both
--column 0
and --column 1
. Finally, you should notice that the uniquify.py
file contains a total of three different procedures for performing
uniquification, with more approaches outlined in the blog post called Fastest
Way to Uniquify a List in
Python.
You should make sure to run the datauniquifier
with at least the three
required ways to remove duplication, checking to see if different approaches
vary in terms of their memory consumption and execution time. Along with
noticing the trends in the data sets that you collect, you should also aim to
explain why these trends are evident, leveraging your knowledge of how the
Python programming languages uses discrete structures such as the set.
The evaluation metrics for the efficiency of the datauniquifier
program are as
follows: (i) execution time of the approach, (ii) estimated memory overhead of
the entire Python program, (iii) reduction in the size of the column of data,
and (iv) percent reduction in the size of the column of data. As you are working
to understand each of these evaluation metrics, make sure that you review the
following Python functions that respectively calculate the reduction and percent
reduction in the size of the data. In the calculate_reduction
function, line
3
calculates and returns the difference in size between the length of the
list_final
and the list_start
, with larger values suggesting that there was
a greater reduction in the size of the list. Finally, lines 3
through 5
in
calculate_percent_reduction
use the output of the calculate_reduction
function to compute the percent reduction when the size of list_start
is
compared to that of list_final
, with higher values indicating a greater
overall reduction in size.
1 2 3 |
|
1 2 3 4 5 |
|
As you conduct the experiment using the datauniqifier
program, you should ask
yourself what type of values would suggest that the tool worked well. For
instance, if you want to reduce the overall size of a data set through the
process of uniquification, is it better to have a large or a small value for
these two evaluation metrics calculated by calculate_reduction
and
calculate_percent_reduction
? Remember, part of your goal for this assignment
is to evaluate how the different configurations of the datauniquifier
program
influence these four evaluation metrics! To accomplish this task you will need
to run the datauniqifier
with different command-line arguments and record
the time and memory overhead data that it reports in your terminal window.
One noteworthy aspect of this program is that it uses the getattr
function to
"construct" an executable version of a Python function when provided with the
name of the function, as described in this StackOverflow
discussion.
After reading the discussion on StackOverflow, make sure that you understand the
source code line unique_result_list = function_to_call(data_column_text_list)
.
You should also notice that, instead of accepting as input the full name of a
function, this program accepts the name of the approach and then builds up the
name of the function. Can you find and understand the source code that completes
this task? Finally, this approach adopts a different approach to recording the
execution time of the three functions that perform uniquification, leveraging
the timing "decorator" described in the following function. Make sure that you
review the following StackOverflow
discussion
to understand how this approach works!
def timing(function):
"""Define a profiling function for execution time."""
@wraps(function)
def wrap(*args, **kw):
ts = time()
result = function(*args, **kw)
te = time()
print("The function %r took: %2.4f sec" % (function.__name__, te - ts))
return result
return wrap
Running Checks¶
As you continue to add and confirm the correctness of datauniquifier
's
functionality, you should study the source code in the pyproject.toml
file.
This file contains the specification of several tasks that will help you to
easily run checks on your Python source code. Now, you can run commands like
poetry run task lint
to automatically run all of the linters designed to check
the Python source code in your program and its test suite. You can also use the
command poetry run task black
to confirm that your source code adheres to the
industry-standard format defined by the black
tool. If it does not adhere to
the standard then you can run the command poetry run fixformat
and it will
automatically reformat the source code. By following a
tutorial,
you can configure VS Code to use the black
tool to automatically reformat the
source code when you save a file.
Along with running tasks like poetry run task lint
, you can leverage the
relevant instructions in the technical
skills to run the command
gatorgrade --config config/gatorgrade.yml
to check your work. If your work
meets the baseline requirements and adheres to the best practices that proactive
programmers adopt you will see that all the checks pass when you run
gatorgrade
. You can study the config/gatorgrade.yml
file in your repository
to learn how the
GatorGrade program runs
GatorGrader to
automatically check your program and technical writing. If your program has all
of the anticipated functionality, you can run the command poetry run task
test-silent
and see that the test suite produces output like the following. It
is important to note that datauniqifier
comes with three test suites, each of
which, as shown below, should pass so as to establish a confidence in program
correctness.
tests/test_analyze.py ...... [ 54%]
tests/test_extract.py .. [ 72%]
tests/test_uniquify.py ... [100%]
Note
Don't forget that when you commit source code or technical writing to your
GitHub repository for this project, it will trigger the run of a GitHub
Actions workflow. If you are a student at Allegheny College, then running
this workflow consumes build minutes for the course's organization! As such,
you should only commit to your repository once you have made substantive
changes to your project and you are ready to confirm its correctness. Before
you commit to your repository, you can should run checks on your own computer
by running gatorgrade --config config/gatorgrade.yml
.
Project Reflection¶
Once you have finished both of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file. For
instance, you should provide the output of the Python program in a fenced code
block, explain the meaning of the Python source code segments that you
implemented, and answer all of the other questions about your experiences in
completing this project. The finished version of your reflection should fully
describe the influence that the size of the input data set, the procedure chosen
for performing uniquification, and the type of data that is input into the
uniquification procedure has on the memory and time efficiency of the process
and the amount of size reduction achieved by a specific configuration.
Project Assessment¶
Since this project is an engineering effort, it is aligned with the evaluating and creating levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet every aspect of the project's specification.
Note
Before you finish all of the required deliverables required by this project is worth pausing to remember that the instructor will give advance feedback to any learner who requests it through GitHub and Discord at least 24 hours before the project's due date! Seriously, did you catch that? This policy means that you can have a thorough understanding of ways to improve your project before its final assessment! To learn more about this opportunity, please read the assessment strategy for this site.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.
Text Processing¶
Project Goals¶
This engineering effort invites you to investigate how to use various discrete
structures, such as the list and the set, to analyze all of the text in a
file. This means that your program, called textanalysis
, must complete tasks
like (i) inputting a text file and storing its contents in a string, (ii)
extracting the paragraphs from the text file, and (iii) extracting the words in
each paragraph. Next, textanalysis
should identify the unique words in each
paragraph, the unique words in the entire document, and the words that are
evident in all of the paragraphs of the document. To accomplish these tasks your
program will use external packages, such as
supervenn, that make it possible to
better visualize and understand the relationships between the sets that
represent each of the paragraphs in the document. As you enhance your knowledge
of discrete structures and your technical
skills, you will continue to
program with VS Code, the Python programming language, and the Poetry package
manager. Ultimately, your goal for this project is to create a program that can
automatically analyze a complete text document.
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to add source code and documentation to the
project!
Note
If you are an emerging proactive programmer who is not enrolled in a Computer Science class at Allegheny College, you can still work on this assignment! To get started, you should click the "Use this template" button in the text-analysis-starter GitHub repository and create your own version of this project's source code. After creating your GitHub repository, you can follow all of the other steps!
Expected Output¶
As part of this assignment, you are going to implement a textanalysis
program
that takes as input a complete document stored in a text file and then performs
an automated analysis of the document's contents. For instance, here is an
excerpt of a text file that you could input into your program. Notably, the
entire file has a total of 5 paragraphs that consist of 19 lines, not including
the blank lines that separate the paragraphs.
Make enables the end user to build and install your package without knowing
the details of how that is done --- because these details are recorded in the
makefile that you supply.
Make figures out automatically which files it needs to update, based on which
source files have changed. It also automatically determines the proper order
for updating files, in case one non-source file depends on another non-source
file.
If you run the finished version of the textanalysis
program with the command
poetry run textanalysis --input-file text/input_one.txt --analyze
, where
text/input_one.txt
is the file that contains the above excerpt and the
--analyze
flag tells the program to perform a textual analysis, you should see
the following output in your terminal window. It is worth noting that the
program will also produce additional output that explains how the supervenn
package analyzed the sets representing each paragraph in order to produce its
graphical representation of the text document. You can learn more about both the
way in which supervenn
uses the FrozenSet
discrete structure and how you
should interpret the visualization that supervenn produces by visiting the
supervenn web site. To see the
visualization produced by supervenn
you should use a graphics preview program
to load the file graphics/set-visualization.png
. For the input file called
text/input_one.txt
, what trends does the visualization show you about the
overlap between the words in the document's paragraphs?
✨ Let's characterize the file and its words!
The input file contains 23 lines, including blank lines!
The input file contains 19 lines, not including blank lines!
The input file contains 5 paragraphs!
The input file contains 118 unique words across all sets!
The words that are found across all sets are: {'Make', 'to'}
🖌 Saving the visualization in graphics/set-visualization.png
Note
Don't forget that if you want to run the textanalysis
you must use your
terminal to first go into the GitHub repository containing this project and
then go into the textanalysis
directory that contains the project's
code. Finally, remember that before running the program you must run poetry
install
to add the dependencies.
Adding Functionality¶
If you study the file textanalysis/textanalysis/main.py
you will see that it
has all of the functionality needed to implement the entire command-line
interface. Furthermore, the file textanalysis/textanalysis/visualize.py
shows
that it also has all of the functions needed to use supervenn
the create a
visualization of the word-level overlap in the provided text file. For this
assignment, the textanalysis/textanalysis/extract.py
file contains the TODO
markers that explain how to implement the following functions.
def extract_lines_including_blanks(input_lines: str) -> List[str]:
def extract_lines_not_including_blanks(input_lines: str) -> List[str]:
def extract_paragraphs(input_lines: str) -> List[str]:
def extract_unique_words_paragraphs(paragraphs: List[str]) -> List[Set[str]]:
def extract_unique_words(sets: List[Set[str]]) -> Set[str]:
def extract_common_words(sets: List[Set[str]]) -> Set[str]:
You can study the source code in the textanalysis/textanalysis/main.py
file to
see the input and expected output of each of the above functions. For instance,
here is the way in which the main
function in the main.py
file calls the
first function in the above list: input_line_count =
len(extract.extract_lines_including_blanks(input_text))
. Note that it accepts
as input the str
called input_text
that contains the textual input from the
file specified on the command-line interface.
The following code segment provides the complete implementation of the
extract_lines_including_blanks
function. The function signature on line 1
shows that extract_lines_including_blanks
will accept a str
as input and
return a List
of str
as output, with each index in the List
being a single
line inside of the input str
called input_lines
. Line 3
of this function
uses the splitlines
function to create the required List
of str
and then
line 4
returns it. It is important to note that this function does not filter
out the blank lines that splitlines
returns — which is the job of the
def extract_lines_not_including_blanks(input_lines: str) -> List[str]:
function that you also need to create! Once you have implemented the required
functions, the textanalysis
should produce the expected output.
1 2 3 4 |
|
Running Checks¶
As you continue to add and confirm the correctness of datauniqifier
's
functionality, you should study the source code in the pyproject.toml
file.
This file contains the specification of several tasks that will help you to
easily run checks on your Python source code. Now, you can run commands like
poetry run task lint
to automatically run all of the linters designed to check
the Python source code in your program and its test suite. You can also use the
command poetry run task black
to confirm that your source code adheres to the
industry-standard format defined by the black
tool. If it does not adhere to
the standard then you can run the command poetry run fixformat
and it will
automatically reformat the source code. By following a
tutorial,
you can configure VS Code to use the black
tool to automatically reformat the
source code when you save a file.
Along with running tasks like poetry run task lint
or poetry run task mypy
,
you can leverage the relevant instructions in the technical
skills to run the command
gatorgrade --config config/gatorgrade.yml
to check your work. If your work
meets the baseline requirements and adheres to the best practices that
proactive programmers adopt you will see that all the checks pass when you run
gatorgrade
. You can study the config/gatorgrade.yml
file in your repository
to learn how the
GatorGrade program runs
GatorGrader
to automatically check your program and technical writing. If there are checks
that did not pass correctly, which you can see in either your terminal window
or through the logs available from GitHub Actions, then you should read them
carefully and take the suggested steps to repair the problems.
Note
Don't forget that when you commit source code or technical writing to your
GitHub repository for this project, it will trigger the run of a GitHub
Actions workflow. If you are a student at Allegheny College, then running
this workflow consumes build minutes for the course's organization! As such,
you should only commit to your repository once you have made substantive
changes to your project and you are ready to confirm its correctness. Before
you commit to your repository, you can should run checks on your own computer
by running gatorgrade --config config/gatorgrade.yml
.
Project Reflection¶
Once you have finished both of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file. For
instance, you should provide the output of the Python program in a fenced code
block, explain the meaning of the Python source code segments that you
implemented, and answer all of the other questions about your experiences in
completing this project. One of the main goals of the reflection is for you to
explain the trends that you see in the different provided text files. You should
also discuss how the textanalysis
program uses discrete structures like the
list
and the set
to automatically characterize the text of a complete document.
Project Assessment¶
Since this project is an engineering effort, it is aligned with the evaluating and creating levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet every aspect of the project's specification.
Note
Before you finish all of the required deliverables required by this project is worth pausing to remember that the instructor will give advance feedback to any learner who requests it through GitHub and Discord at least 24 hours before the project's due date! Seriously, did you catch that? This policy means that you can have a thorough understanding of ways to improve your project before its final assessment! To learn more about this opportunity, please read the assessment strategy for this site.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.
Collatz Creation¶
Project Goals¶
This engineering effort invites you to investigate how to apply all that
you have learned about Python programming and discrete structures to
implement a program, called collatzcreation
, that can solve the
Longest Collatz
Sequence
problem posed on Project Euler. The Collatz
sequence is defined for the positive integers according to the rule that
\(n\) becomes \(\frac{n}{2}\) when \(n\) is even and \(3n + 1\) when \(n\) is odd.
To date, computer scientists and mathematicians do not know whether or
not the Collatz sequence will terminate with the value of \(1\) when it is
started with an arbitrary positive integer \(n\). However, for all of the
values tried to date the sequence always yields a Collatz chain (i.e.,
the sequence values that arise from iteratively applying the rules) of a
finite length. The Longest Collatz Sequence problem posed by Project
Euler asks "Which starting number, under one million, produces the
longest chain"? The collatzcreation
program that you implement for
this project should efficiently produce an answer to this question.
Project Access¶
If you are a student enrolled in a Computer Science class at Allegheny College,
you can access this assignment by clicking the link provided to you in Discord.
Once you click this link it will create a GitHub repository that you can clone
to your computer by following the general-purpose instructions in the
description of the technical
skills. Specifically, you
will need to use the git clone
command to download the project from GitHub to
your computer. Now you are ready to add source code and documentation to the
project!
Note
If you are an emerging proactive programmer who is not enrolled in a Computer Science class at Allegheny College, you can still work on this assignment! To get started, you should click the "Use this template" button in the collatz-creation-starter GitHub repository and create your own version of this project's source code. After creating your GitHub repository, you can follow all of the other steps!
Expected Output¶
As part of this assignment, you are going to implement a
collatzcreator
program that takes as input a complete document stored
in a text file and then performs an automated analysis of the document's
contents. If you run the collatzcreator
program with the command
poetry run collatzcreator --minimum 1 --maximum 10 --display
it will
try the numbers 1
through 10
as the input number to the Collatz
Sequence and then calculate the length of the Collatz chain before the
sequence produces the value of 1
. The collatzcreator
program will
also compute some summary statistics about the length of the Collatz
chains that it constructed when using the inputs that start at the
minimum
and go up to the maximum
. When the collatzcreator
accepts
the input flag of --display
it will also produce a graph that will
visualize the relationship between the value of the numerical input and
the length of the Collatz chain.
🕵 Let's investigate the behavior of the Collatz sequence!
The first input to try will be 1
The last input to try will be 10
The inputs to the Collatz function:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
✨ What is the length of the Collatz chain before the function produces
the value of 1?
📏 The length of the resulting Collatz chain:
[1, 2, 8, 3, 6, 9, 17, 4, 20, 7]
✨ What is the summary information about the length of the Collatz chain?
The minimum length of a Collatz chain is: 1
The maximum length of a Collatz chain is: 20
The mean of the length of a Collatz chain is: 7.70
The median of the length of a Collatz chain is: 6.50
The standard deviation of the length of a Collatz chain is: 5.97
🤷 Can you find a pattern between the input number and the length of the
Collatz chain?
📦 Check the file called 'graphs/collatz.pdf' to see a graph that
visualizes the results!
Note
Don't forget that if you want to run the collatzcreator
you must use your
terminal to first go into the GitHub repository containing this project and
then go into the collatzcreator
directory that contains the project's
code. Finally, remember that before running the program you must run poetry
install
to add the dependencies.
Adding Functionality¶
If you study the file collatzcreator/collatzcreator/main.py
you will see that
it contains a single TODO
that reminds you to call the compute_collatz_chain
function that takes as input a specific number and returns an Iterator[int]
as
its output. This means that the compute_collatz_chain
function should use
yield
to incrementally produce the int
values in the Collatz sequence. When
you look at the collatzcreator/collatzcreator/collatz.py
file you will notice
that the TODO
marker instructs you to provide a complete implementation of the
aforementioned compute_collatz_chain
function. Finally, a review of the
collatzcreator/collatzcreator/summarize.py
will show that you also need to
implement the following functions that characterize the computed Collatz
sequences:
def compute_mean(numbers: List[int]) -> float:
def compute_median(numbers: List[int]) -> float:
def compute_difference(numbers: List[int]) -> List[float]:
def compute_variance(numbers: List[int]) -> float:
def compute_standard_deviation(numbers: List[int]) -> float:
The following source code segment provides a complete implementation of the
compute_collatz_chain
function. Line 3
of this function firsts yield
s the
number
since the first numerical value in the Collatz chain is always the
initially provided number. Next, lines 4
through 9
iteratively compute the
values in the Collatz sequence, continuing until the number
takes on the value
of 1
. When number
is even, lines 5
and 6
use the //
operator to assign
to number
to the integer value of number / 2
. When number
is odd, line 8
assigns to number
the value of 3 * number + 1
. Ultimately, the
compute_collatz_chain
function follows the sequence's definition by which \(n\)
becomes \(\frac{n}{2}\) when \(n\) is even and \(3n + 1\) when \(n\) is odd, only
terminating when the value of \(n\) is \(1\).
1 2 3 4 5 6 7 8 9 |
|
Finally, don't forget that the Longest Collatz
Sequence problem
posed on Project Euler is "Which starting number,
under one million, produces the longest chain"? This means that you will need to
run the program with the following command-line arguments: poetry run
collatzcreator --minimum 1 --maximum 1000000 --display
. It is important to note
that it is possible that running collatzcreator
on your laptop with these
command-line arguments may require a significant amount of computation time.
This means that you will either have to wait a long time for collatzcreator
to
finish or implement a more efficient version of the compute_collatz_chain
function! Which approach did you pick? Why?
Running Checks¶
As you continue to add and confirm the correctness of collatzcreator
's
functionality, you should study the source code in the pyproject.toml
file.
This file contains the specification of several tasks that will help you to
easily run checks on your Python source code. Now, you can run commands like
poetry run task lint
to automatically run all of the linters designed to check
the Python source code in your program and its test suite. You can also use the
command poetry run task black
to confirm that your source code adheres to the
industry-standard format defined by the black
tool. If it does not adhere to
the standard then you can run the command poetry run fixformat
and it will
automatically reformat the source code. By following a
tutorial,
you can configure VS Code to use the black
tool to automatically reformat the
source code when you save a file.
Along with running tasks like poetry run task lint
, you can leverage the
relevant instructions in the technical
skills to run the command
gatorgrade --config config/gatorgrade.yml
to check your work. If your work
meets the baseline requirements and adheres to the best practices that
proactive programmers adopt you will see that all the checks pass when you run
gatorgrade
. You can study the config/gatorgrade.yml
file in your repository
to learn how the
GatorGrade program runs
GatorGrader
to automatically check your program and technical writing. You can also run the
command poetry run task test
to run the Pytest test suites provided in the
files test_collatz.py
and test_summarize.py
. Did all of your tests pass?
Note
Don't forget that when you commit source code or technical writing to your
GitHub repository for this project, it will trigger the run of a GitHub
Actions workflow. If you are a student at Allegheny College, then running
this workflow consumes build minutes for the course's organization! As such,
you should only commit to your repository once you have made substantive
changes to your project and you are ready to confirm its correctness. Before
you commit to your repository, you can should run checks on your own computer
by running gatorgrade --config config/gatorgrade.yml
.
Project Reflection¶
Once you have finished both of the previous technical tasks, you can use a text
editor to answer all of the questions in the writing/reflection.md
file. For
instance, you should provide the output of the Python program in a fenced code
block, explain the meaning of the Python source code segments that you
implemented, and answer all of the other questions about your experiences in
completing this project. One of the main goals of the reflection is for you to
explain the trends that you see in relationship between the input number and
the length of the Collatz chain. You should also discuss how the
collatzcreator
program uses discrete structures like the list
or the
tuple
to store the Collatz chain and then visualize its characteristics with
a scatterplot.
Project Assessment¶
Since this project is an engineering effort, it is aligned with the evaluating and creating levels of Bloom's taxonomy. You can learn more about how a proactive programming expert will assess your work by examining the assessment strategy. From the start to the end of this project you may make an unlimited number of reattempts at submitting source code and technical writing that meet every aspect of the project's specification.
Note
Before you finish all of the required deliverables required by this project is worth pausing to remember that the instructor will give advance feedback to any learner who requests it through GitHub and Discord at least 24 hours before the project's due date! Seriously, did you catch that? This policy means that you can have a thorough understanding of ways to improve your project before its final assessment! To learn more about this opportunity, please read the assessment strategy for this site.
Seeking Assistance¶
Emerging proactive programmers who have questions about this project are invited to ask them in either the GitHub discussions forum or the Proactive Programmers Discord server. Before you ask your question, please read the advice concerning how to best participate in the Proactive Programmers community. If you find a mistake in this project, please describe it and propose a solution by creating an issue in the GitHub Issue Tracker.