Answer to Question #190202 in Python for Angelie Suarez

Question #190202

Activity:

1. FizzBuzz

Create a program that will display numbers 1-31. When the number Is divisible by 3, it will print Fizz besides

the number. But when the number is divisible by 5, it will print buzz besides the number. But if the number is

divisible by 3 and 5, it will print FizzBuzz besides the number.

Sample output:

1

2

3fizz

4

5buzz

6fizz

7

8

9fizz

10buzz

11

12fizz

13

14

15fizzbuzz

16

17

18fizz

19

20buzz

21fizz

22

23

24fizz

25buzz

26

27fizz

28

29

30fizzbuzz




1
Expert's answer
2021-05-07T03:36:12-0400
for i in range(1,31):
    if i % 3 == 0:
        print("{}fizz".format(i))
    elif i % 5 == 0 and i % 5 == 0:
        print("{}fizzbuzz".format(i))
    elif i % 5 == 0:
        print("{}buzz".format(i))
    else:
        print(i)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS