13
$\begingroup$

I'm teaching an undergrad Intro to Programming for Non-majors this semester (in Python) and I'm looking for some fun projects for my students that are engaging but not too difficult for them. This is my first go around with this course.

I've looked at their majors to see if I could come up with projects that might relate to it, but that didn't spark any ideas.

Maybe some games, like Tic-Tac-Toe? Does anyone have suggestions that have worked well for them?

Update: These are typical undergrad students at a US university, so about 18 - 22 year olds, with no programming background. The main focus is on imperative rather than OOP. In the past I haven't found an easy way to introduce graphics with Python or GUIs, but perhaps there's some nice stuff out there now. I don't think Turtle graphics would hold their attention very much or very long, also seems more age appropriate to younger students I believe.

$\endgroup$
16
  • 1
    $\begingroup$ graphics is a lot harder in Python than in Java. Let me think about how an idea would work without graphics. $\endgroup$
    – Buffy
    Feb 3 at 13:00
  • 2
    $\begingroup$ I've used Tcl/Tk bindings with Python, but it is painful. $\endgroup$
    – Buffy
    Feb 3 at 13:13
  • 1
    $\begingroup$ @Levon You may check this realpython.com/tutorials/projects I got some ideas from here realpython.com/intermediate-python-project-ideas $\endgroup$ Feb 4 at 6:34
  • 2
    $\begingroup$ Back in the 80s, at high school, we had Commodore PETs. By the end of the 1st semester, I had managed to create a very simple, but playable 'breakout' game, in BASIC. We weren't able to save our programs, so every week, I had to type the program in again from memory. By the end of the term, I was able to type it in, and then play it for 5 minutes before the end of the 30 minute lesson. 'Graphics' doesn't have to mean 3d rendered artwork. Just moving a letter 'O' and '-----' around a console window is graphical enough to play breakout. $\endgroup$
    – Neil
    Feb 4 at 11:51
  • 2
    $\begingroup$ If you give up GUI and settle on 2D graphics with manually generated RGB, you can do something quite easily if you provide your students with a basic pygame structure. Take a look here - my code is pretty much lines 15-30, rest is taken from SO answers. I've programmed for a few years already, but have almost no Python experience. Total time taken: ~2 hours. $\endgroup$ Feb 4 at 21:42

17 Answers 17

11
$\begingroup$

Another fun game is "Spelling Bee" from the New York Times (https://www.nytimes.com/puzzles/spelling-bee). You supply a file containing words. The student program reads the file and selects words that match the rules. The milestones are from a past project from Reed College.

  1. Print all the words that can be spelled using a fixed string (e.g. "AZDIRWY"). The first letter is the required letter.
  2. Prompt the user for a string and print a list of words or take the string as a command line parameter.
  3. Generate a score for each word and the total score.
  4. Generate the graphics to draw the string as it appears in the paper (six hexagons containing optional letters surrounding a central hexagon with the required letter), along with the list of words.

You could potentially go a slightly different direction and let the python program generate HTML output and view the results in a browser. This illustrates dynamically generated HTML.

Another variation would be to preprocess a "dictionary", removing all words that are too short or contain more that seven distinct characters. Then create multiple files, one for each possible beginning letter. You now have cut down the search space. You might also have the students sort the answers, perhaps by word score.

$\endgroup$
1
  • $\begingroup$ Ah .. interesting idea, thank you, I will definitely check this out. $\endgroup$
    – Levon
    Feb 3 at 23:31
10
$\begingroup$

Here is a concept but it works much better with visual feedback.

Simulate a Pandemic.

A pandemic requires a world with inhabitants that can be in one of several states, such as healthy, sick, dead. The pandemic spreads from sick inhabitants to "neighbor" inhabitants who are healthy. "Dead zones" stop the spread. You can also erect barriers to the spread to simulate oceans and such. People can get well or not and be reinfected or not. The pandemic can "jump" to simulate air travel and such.

Such a thing can be highly parameterized for infection rates and everything else.

A two dimensional array can represent the world and you can "attach" the edges in various ways to simulate a sphere or torus or möbius strip.

The simulation runs through iterations.

If you want to think of the whole thing as MVC, what I've described is the Model part, which normally is independent of the Views and Controllers in any case.

The idea is stolen from a book, Polymorphism Companion, but there is enough above to build it.

$\endgroup$
6
  • $\begingroup$ Thanks .. I'm not sure I'd want to hoist more pandemic type themed work on them give that the world around us is dealing with it. However, this reminded me of a similar project where wildfires were simulated - so very close, but different theme. Thanks for the reference too. $\endgroup$
    – Levon
    Feb 3 at 23:26
  • 14
    $\begingroup$ Given that some students may have lost loved ones to the coronavirus pandemic, I think this topic should be treated very sensitively if at all. Doing a similar kind of simulation task with a different context could well be a good idea. $\endgroup$
    – kaya3
    Feb 3 at 23:55
  • $\begingroup$ Honestly, isn't this just putting a story behind Conway's Game of Life? With some probability elements added, that is. $\endgroup$ Feb 4 at 20:06
  • $\begingroup$ @JanDorniak, similar, but you can make it a realistic simulation if you work at it. You can model lots of things with this basic structure. $\endgroup$
    – Buffy
    Feb 4 at 20:26
  • $\begingroup$ This seems pretty complicated for non-CS majors with no programming background. The concept could be fun, with a special exception for a small number of individuals (see kaya3's comment), but the problem being solved sounds really involved for something being used by a lot of the students like a 2nd year elective. $\endgroup$ Feb 5 at 13:04
6
$\begingroup$

As a non-CS adult, when I'm learning a new language I like to write programs to solve some of the Project Euler problems. Stick to the lower numbered problems and they're not too hard for non-mathematicians.

For me, these problems are fun. There is enough information given in the problems to make sure that non-mathematicians understand the goal.

Good Luck!

$\endgroup$
3
  • 2
    $\begingroup$ Interesting, though it is perhaps a bit to much like math. I don't like to give the students the impression, early on, that CS is just a branch of math. But, given that the OP wants to emphasize imperative programming (hmmm, why use Python) this will do the job. There is a current discussion on the SIGCSE mailing list about whether CS is a branch of engineering. It is worth a look and some thought. $\endgroup$
    – Buffy
    Feb 4 at 13:47
  • $\begingroup$ I also enjoy Project Euler (thanks for reminding me) - perhaps one or two of those simpler problems could be appropriate. I used it to bone up on my maths, the coding was easy :) .. @Buffy Python because it's a friendly language with a low entry barrier :) , and in wide use (some of my students are interested in informatics, so that's good too). Also, I'm not so much emphasizing imperative coding, more accurately perhaps, I just won't get too much (or perhaps at all) into the OOP aspects (though they will use objects of course). $\endgroup$
    – Levon
    Feb 4 at 14:57
  • $\begingroup$ This is how I got started learning programming but I think the mathematical/non-programming-analysis barrier becomes prohibitive for most people relatively quickly, within fewer than say 50 problems. $\endgroup$
    – Ian
    Feb 6 at 21:38
4
$\begingroup$

For the imperative decision making aspects, one of the best approaches I have personally found for getting people interested is to have them write programs that play a game (not writing the game itself, but writing a program that can stand in for a human playing the game).

This challenges them to think analytically about how the game is played, and that analytical thinking is one of the single most important things to learn to be good at programming.

The card game twenty-one (blackjack/pontoon/vingt-un) is an example of an easy starting point, because:

  • The rules are very simple, easily explained in about five minutes even to someone who has never heard of the game before.
  • The resultant programs tend to be very compact and run very fast (meaning you can run each student’s program hundreds of thousands of times to get a good idea of how it performs). It’s actually possible to write a basic AI for twenty-one in only a few dozen lines of code.
  • A simple but near optimal strategy comes intuitively to most people (namely, keep taking new cards until you are at or above a specific value (most people tend to prefer somewhere around 18) and then pass).
  • A truly optimal strategy requires actually evaluating what the other players have and figuring out the probability of taking a new card putting you over 21 based on that.

From there, you can branch out into other simple games. Card games tend to work very well for this because they force the students to account for basic probability to have their program do well, but also generally require more than just probability for an optimal strategy.

With a bit of extra prep-work, you can even set this up as a ‘tournament’ type thing (ideally not affecting grades, because that gives a bit of an unfair advantage to those who have the skills to figure out a truly optimal strategy) as a way to encourage those in the class who enjoy competition.

$\endgroup$
1
  • 1
    $\begingroup$ I'm a big believer in "extra prep work". I normally provide some scaffolding for projects, especially important ones. $\endgroup$
    – Buffy
    Feb 4 at 13:45
3
$\begingroup$

Python turtle

Related to what their major is if you can find something relevant else import turtle # this module allows some visual output, that can be interesting, and gives good feedback.

Jupiter notebooks / google colab notebook.

It allows you to create pages using markdown (same as this site), and to incorporate python code, tables, and charts. Tables can be input or output, charts are output, there are other inputs such as sliders. This is good for any one with a scientific interest, as they can continue using it in their major.

Linguistic analysis / text generation

Write a program to create writing in the style of. You can do this with a 2 stage markov chain (a what?). You just generate a table containing the probability of the next word. e.g. for the short phrase "the cat sat on the mat", both "cat" and "mat" have a 0.5 probability of following a "the". With a long enough training text, you can get it to generate its own texts.

You will have to write the program for them, or at least partly. What you write must work, but not be complete, so that they can add to it. But now I am digressing onto an answer for another question.

$\endgroup$
5
  • $\begingroup$ I appreciate the suggestion re Turtle graphics, I have to think about it, my initial reaction is that this would be more age appropriate to younger students (these are undergrads, so 18 - 20) though I guess it could be used to help demonstrate concepts, looping and writing functions come to mind. $\endgroup$
    – Levon
    Feb 3 at 12:58
  • 1
    $\begingroup$ I added two more suggestions. I agree that the turtle may be better of younger students. The hard bit is finding something relevant (and this depends on their interests), so maybe a mixture of things. $\endgroup$ Feb 3 at 14:27
  • $\begingroup$ Thanks for expanding on your answer. The Jupyter notebook is something I hope to introduce them to at some point toward the end of the course, esp since it is relatively easy to plot data in the notebook and visualize it. Maybe scikit has something I can use for the text based idea, I'll have to check it out. $\endgroup$
    – Levon
    Feb 3 at 23:30
  • 1
    $\begingroup$ @Levon For an intro to programming course, you probably don't want to assume much about the level of understanding of the students - particularly if they're coming from other majors. At least a few weeks covering basics like loops/functions is almost a must. An intro course I took (as a CS major, but other majors were in the class) used Python and had us use Turtle to draw a variety of country flags in the second week, and some people did struggle with that. Depending on what majors are included in your class, some may never have written a line of code in their lives. $\endgroup$
    – Kayndarr
    Feb 4 at 1:57
  • $\begingroup$ @Kayndarr Yes I agree that you must start at the beginning. The trick is choosing the correct beginning. $\endgroup$ Feb 4 at 19:38
3
$\begingroup$

At my institution, we (often) take our courses' final products in a different direction: free choice, working as a pair (or in a trio).

Students write 2 to 3 ideas ("proposals") within a google doc, and then talk among themselves to find projects that seem like a good fit.

They then write up short proposals, and divide tasks into "must-have for a minimum viable product", "important", and "nice-to-have". We added this step after years of watching some subset of students get completely lost in the weeds. We came to call them the "font color" students, and we found that having that list upfront enables us to point back to it and redirect the students towards the most important parts of the project.

They have a few weeks to work when the teachers walk around the room offering support, and then they give a final presentation.

The final product is not a huge portion of the grade, because a fair number of the projects don't quite come together. We consider that developmentally appropriate; students are very poor at gauging how much they can get done in 2 weeks and how long things will take. Free projects also force students to explore new avenues, and we did not want to penalize such explorations, as learning how to wrap your brain around new libraries and new challenges is both hard and virally important.

Instead, the students give a presentation on what they wanted to produce and what libraries they used, and then they demo what they have and reflect on what went well and what could have gone better. Personally, I also add in a requirement that students show us one interesting thing in their code, though my colleagues do not do this. In any case, the presentations are a lot of fun, and some number of the projects are always very impressive. It's a fun way to end a course on a nice, uplifting note.

$\endgroup$
1
  • $\begingroup$ I believe this approach would be an option once COVID times are over, thank you for sharing. $\endgroup$
    – Levon
    Feb 3 at 23:24
3
$\begingroup$

Web scraping is a vast domain that might interest students. Python is great for string matching (the power of regular expressions!), for parsing HTML (or XML or JSON) into structures that are so much more simple to manipulate.

There are even sites that provide APIs to help. The Python Praw library allows you to wander down Reddit pages your students may already be reading, using just a few lines of code.

There are RSS parsers to be constantly in the know, with many site providing RSS feeds.

From there, you can progress to selenium to show how bots click buttons for you, and can warp reality into the fake world we see, with so little effort.

$\endgroup$
2
  • $\begingroup$ Thanks for the suggestion, I already showed them some simple code to automate the opening of some web sites for them, this may fit nicely with this. $\endgroup$
    – Levon
    Feb 5 at 12:18
  • 1
    $\begingroup$ Note about parsing HTML with regular expressions: stackoverflow.com/a/1732454/2436687 It's good enough for playing and learning regexes, but for more serious uses, Python has a HTML parser in the standard library. $\endgroup$
    – user31389
    Feb 5 at 14:09
2
$\begingroup$

It is not said for how much time the students shall dedicate to their projects, e.g., as an exercise / lab class, or for a (perhaps multiple) week long one. If aiming for shorter ones, I recommend to find inspiration from the sources teaching «this is the problem x, along which we develop technique y». Seek-out for projects which may simplify the day-to-day work for the attendees. Sources of inspiration then could be

The listing above can't be exhaustive.

$\endgroup$
1
  • $\begingroup$ Thanks .. I'm familiar with the Sweigart book (use some of it for my own) and plan to show some of this to the students. Not familiar with the others, but will check them out. $\endgroup$
    – Levon
    Feb 4 at 14:53
2
$\begingroup$

Sound is another subject that can be as simple or complex as you like. The format of a wav file is already pretty complex. You can read the header in Python, and then decode the pcm data stream and, for example, write a new file with half the volume. It should be easy to verify by ear if your program got it right! By only reading and writing files the tricky business of handling audio hardware can be avoided.

Even with this simple format, there are lots of things to try, like detecting and removing silence, or almost silence; converting stereo to mono; re-sampling at a lower rate; generating a sine wave tone at 440hz; superimposing tones; fading two files into one; calculating the average volume every 10 seconds and drawing the envelope shape down the terminal like a cash till printer; drawing a VU meter on the terminal using carriage-return to go back to the start of the line. Perhaps you can find out how shazzam identifies music?

I see there is now a Python wave library to simplify things once the basics have been understood. There is also a pyaudio library to play and record streams, and I see examples using matplotlib for the graphics, which is going a bit far. For non-dynamic output, the SVG format could be interesting, as it is directly viewable in a browser, and there are some Python libraries for it.

$\endgroup$
1
  • $\begingroup$ Thanks, I like a multimedia approach, may try this next time. In the meantime I'd have to get more familiar with audio files and the relevant libraries myself so that I could help students and flesh out assignments. Thanks for the suggestion. $\endgroup$
    – Levon
    Feb 5 at 22:36
2
$\begingroup$

I teach first/second semester students C, and what I usually do is start with rather simple tasks like finding out whether a year is a leap year, a wordcount (wc) or ls program etc.

Later I progress to "projects". Most of thess---this is C after all---are simply taken from UNIX console utilities:

  • nc: Connect to TCP/UDP/UNIX sockets or listen on them
  • tar: Archive (not compress!) files. This is actually surprisingly easy! Bonus benefit that their archive files can be decompressed by other tar Programs!
  • PCM picture manipulation: PCM is a simple text based picture format. They can build programs to manipulate saturation or invert colors and then display them in an image viewer
  • interactive PCM picture manipulation: The previous can be expanded, with SDL in our case, to also draw a simple GUI.
  • snake: Either with SDL or curses/termbox

In my experience, all can be implemented after roughly a week. The specific project to choose is up to themselves, they can also implement their own ideas after speaking with us.

$\endgroup$
2
$\begingroup$

Other cool game with simple logic to it would be Conway's game of life.

https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life

$\endgroup$
2
  • $\begingroup$ That's one of my favorite games, but may be a bit beyond newbie programmers, unless I find and set up some sort of framework to visualize this and they just work with the rules. $\endgroup$
    – Levon
    Feb 11 at 0:49
  • 1
    $\begingroup$ Think console and they only need to use spaces and O, 0, or even '.' for active cells makes things much easier. Just suggest widths and heights that match the console so each refresh scrolls the old one off the screen so no clear screen is needed. If they use an array of strings the data and the visual can be the same which should make a lot more sense to them then say a boolean 2d array and having to translate it for display. The rules for neighboring cells is much harder then displaying the results. $\endgroup$
    – Dragonaire
    Feb 11 at 22:26
1
$\begingroup$

I know for me, personally, when I'm learning a new language, what helps me most is to have a means of collecting simple user input through a console. (Text or numbers, that's all) What this allows me to do is make simple "games" that don't focus a lot on graphics/presentation/game design, but rather execution. It allows me to focus on figuring out how I can use the least code possible, how I can organize data in the best ways, how to disassemble the user's input into something that my program can read/respond to, etc, etc.

I recently learned Java, and mid way through learning I challenged myself to make an infinite math game. This was a game that would procedurally generate very simple math problems, solve them, present them to the player, and then compare the player's input to the solved problem. If they matched, I add to the player's score and allow them to move on, if they don't match, I end the game and present the player with their score. (And also reveal the correct answer)

Then, once I was more advanced in Java, I challenged myself to make an infinite word game. Which was more challenging, but in all different ways. It kept it very interesting. The math game was hard to make because I had to think up a way to put together numbers + operators into a string, while also keeping them as something that Java could evaluate into an answer, however the word game was hard because I had to find a way to store many many words and pick from them randomly. Additionally, I challenged myself to allow the player to use "hints" to reveal a single letter of the word, and every time they used one it would reveal the next letter, in order. I also added categories and organized the words that way to add additional challenge for myself.

I'm not sure these games exactly would be a good fit for you or your students (and I don't expect that they will be) but hopefully something along these lines could be very fun for them and challenge them in all the right ways. Hope this helps.

$\endgroup$
1
$\begingroup$

MicroPython

I'd like to suggest that you look at MicroPython, not because it is a subset of Python, but because it runs on a growing number of microcontrollers, and there are many complete educational projects built on them.

For example, for about $9 you can get the m5atom which is a read-to-use device that you can plug in to usb, where it appears as a serial port. You download a Python source file to it, and your code can draw on the led display, detect button presses, send infra-red codes, detect movement, listen to Bluetooth, use Wi-fi.

There are many other manufacturers providing similar devices and environments, such as the new Raspberry Pi Pico and the BBC micro:bit, and Adafruit (they call their version CircuitPython), for the same or even lower prices, though you don't need to buy a device per person.

No need for an IDE (though I believe there are some). A simple command line program lets you talk to the python interpreter directly, or use it to download a Python file. Or some manufacturers provide an in-the-browser IDE (example) that can simulate and/or download the resulting source into the device over usb.

There is something very rewarding about seeing something physically tangible happen when you run your code.

$\endgroup$
2
  • $\begingroup$ Thanks for the suggestion, I will check this out, not not for them, for me for sure :) I use Thonny as the Python IDE, very highly recommended for newbie programmers, in this class which has support for MicroPython (how I heard about it in the first place). It may be too late for this term, but definitely something to consider for next time I teach this course a year from now, hopefully back on campus. I have used the Raspberry Pi before in class (more advanced elective Linux class based on group projects) $\endgroup$
    – Levon
    Feb 5 at 12:20
  • 1
    $\begingroup$ I was going to add an answer much like this - consider a simple hardware-related project - especially one where with advance planning you could arrange to have already built hardware - consider this persistence-of-vision toy - programmed via microprolog, you can spin it on its axis, as here, or whirl it about at the end of a string, wire wrap it to a bicycle wheel, or who knows what. Could cost <$25 I imagine, if prebuilt there'd be no time pressure for the project on that score, fun, creative, etc. etc. $\endgroup$
    – davidbak
    Feb 5 at 18:15
1
$\begingroup$

Make a Snake (Python) game

My very first class in collage (CS) was to make a snake game. We got some code (like input control and rendering) and just had to connect the pieces and do some simple coding. This class was basically to get everybody comfortable with using the IDE and coding.

The good thing was that those of us that found it very easy could add improvements to the game like sound and better graphics. And the teacher could concentrate on helping those that needed basic help.

https://en.wikipedia.org/wiki/Snake_(video_game_genre)

$\endgroup$
1
  • 1
    $\begingroup$ I do like the idea of a project that can be continued to be improved upon by the strong students, and that's also a longer term project that can evolve during the semester. Thanks for the suggestion. $\endgroup$
    – Levon
    Feb 5 at 22:38
1
$\begingroup$

Design a Vending Machine

A straight forward project that I've seen used and worked through myself is to implement a vending machine. Pretty much everyone knows how a vending machine works, so there isn't a learning curve on what the requirements are.

It can be really simple, using a command line interface to enter money, select an option, and get change back.

You could add basic inventory management, keeping track of how many of each item are available - even storing the current inventory in a file, giving the need to work with persisting data in a variety of file formats (simple text file, JSON/YAML)

After the command line version is working, they can learn to create a GUI to represent the vending machine, using the same underlying code. This can help to discover the need to separate business logic from representation.

$\endgroup$
1
  • $\begingroup$ Neat, thanks - I can think of a number of ways working with this project. $\endgroup$
    – Levon
    Feb 5 at 22:38
1
$\begingroup$

Sudoku game/solver can be a fun project. I did this in my C/C++ class but should be good for Python as well. At the same time I did a Rust version so those that might be interested could compare them ;)

$\endgroup$
2
  • 1
    $\begingroup$ I'm worried that this might be a bit too challenging of an algorithm for newbie programmers, no? $\endgroup$
    – Levon
    Feb 8 at 22:09
  • 1
    $\begingroup$ For a student that already knows the game I don't think so. I had never tried Sudoku before but was able to have it working within a week or less. I spent more time on the visual output and input processing then the logic. They will need to understand functions and arrays so probably mid-term or later project in most classes. $\endgroup$
    – Dragonaire
    Feb 10 at 20:41
1
$\begingroup$

For simple, but interesting, problems and guidance on language use consider Downey's "Think Python" (Green Tea Press, 2nd edition). Make sure to pick the second edition (Python 3), the first one is Python 2 only. The full source to the book, exercises, and other material is available for free.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.