Mark As Completed Discussion

Examples

Let's explore some practical examples to further solidify our understanding of the concepts we have covered so far.

Example 1: FizzBuzz

Let's start with a classic example called FizzBuzz. In this problem, we need to print integers from 1 to 100, but for numbers divisible by 3, we print 'Fizz', for numbers divisible by 5, we print 'Buzz', and for numbers divisible by both 3 and 5, we print 'FizzBuzz'.

Here's the Python code to solve the FizzBuzz problem:

PYTHON
1if __name__ == "__main__":
2  # Python logic here
3  for i in range(1, 101):
4    if i % 3 == 0 and i % 5 == 0:
5        print("FizzBuzz")
6    elif i % 3 == 0:
7        print("Fizz")
8    elif i % 5 == 0:
9        print("Buzz")
10    else:
11        print(i)
12
13  print("Print something")

When you run this code, it will print the numbers from 1 to 100, replacing numbers divisible by 3 with 'Fizz', numbers divisible by 5 with 'Buzz', and numbers divisible by both 3 and 5 with 'FizzBuzz'.

Example 2: [Add your example here]

You can add additional examples here to showcase other concepts or programming problems.

By practicing these examples, you will gain hands-on experience and reinforce your knowledge of the course material.

Keep exploring and experimenting!

PYTHON
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment