Save this video free

Python (Fall 2026) Module 13-2: Writing Recursive Code

Bill Moseley, Ph.D. - Computer Science Educator · 14:29 · Watch on YouTube

Python (Fall 2026) Module 13-2: Writing Recursive Code Watch on YouTube →

Overview

Bill Moseley demonstrates recursion in Python by building a countdown function that prints its argument, checks whether it is greater than zero, and calls itself with one less. He uses the debugger and a “waking up” print statement to show how recursive calls unwind, then develops a count-up function and explains why every recursive function needs a stopping condition to avoid Python’s roughly 1,000-call recursion limit.

Key takeaways

Chapters

0:00 Building a Recursive Python Countdown
4:30 Tracing Recursive Calls and Their Unwinding
10:00 Writing countUp and Preventing Infinite Recursion

Keep these chapters and the full searchable transcript in your own library.

Transcript excerpt

0:00 Let's write some recursive code right now.  Why don't you fire up PyCharm? I'm going to give you a minute to get it going before I  write any code, but go ahead and fire it up. And we're going to do a simple  recursive function together. Yes. Yep. Yep. And you'll see exactly what I mean  by that here in just a minute. But basically, the definition of a function contains  a call to that function. So that it actually calls itself, a dream  inside a dream inside a dream.

0:57 All right. So I'll start nice and slow here  with this. But we are going to create a function that will count down from any number  we give it to zero and stop. While you do, while you get Python ready to go,  I'm going to show you how this would work in a non-recursive function.  Right? I would say for int, range, I might say 10 comma 0 comma 1, and I would print int. So  if I run this, there we go, counts from zero to, or 10 to one. Now, if I  wanted to make that inside a function, I might

1:58 say def countdown, and I would say intStart for  the starting integer. And then all I do is take that number and put it here. intStart. And maybe I  go to negative one. So it'll stop at zero. Right? So now if I want to call that function, I  would say countdown 100, and it's going to count down from 100 all the way to zero.  Now that is a non-recursive example. And I will be honest with you, the recursive  version of this isn't really a timesaver. This isn't, this isn't, counting down from a  number to zero isn't really a problem that I

2:49 would use recursion for typically, but let's do it  anyway. So, I'm going to remove the, in the parts

This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.

Related notes

Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Bill Moseley, Ph.D. - Computer Science Educator.

Want the full transcript?

Save this video in YouTube Collector to get its complete searchable transcript, your own AI summaries, and a library that keeps every video you collect in one place.