From the course: Programming Foundations: Data Structures (2023)
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Challenge: Generate binary numbers - Python Tutorial
From the course: Programming Foundations: Data Structures (2023)
Challenge: Generate binary numbers
- [Narrator] Let's practice using cues in Python. In this challenge you'll use a queue to generate the first n binary numbers. Your function will take in a number n as input, and print out the first n binary numbers. As a reminder, a binary number is a number that consists of 0s and 1s, and it's on the base-2 numeral system. These are some examples of binary numbers. We start off with 1, which maps to 1 in the binary system, 2 maps to 10, 3 maps to 11, 4 maps to 110, and so on. Let's think about how this applies to our algorithm. If the input was 6, your algorithm would print out, 1, 10, 11, 100, 101, and 110. If the input is less than or equal to 0, the algorithm should print out nothing. For this challenge, consider looking for a pattern and using that pattern with a queue to generate future binary numbers. Good luck and happy coding.