Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Fizzbuzz project #3

Open
Raashika0201 opened this issue Oct 2, 2022 · 3 comments
Open

Add Fizzbuzz project #3

Raashika0201 opened this issue Oct 2, 2022 · 3 comments

Comments

@Raashika0201
Copy link

No description provided.

@vivekdeme
Copy link

Write a Python program that iterates the integers from 1 to 50. For multiples of three print "Fizz" instead of the number and for multiples of five print "Buzz". For numbers that are multiples of three and five, print "FizzBuzz".

Solution:

Python Code :
for fizzbuzz in range(51):
if fizzbuzz % 3 == 0 and fizzbuzz % 5 == 0:
print("fizzbuzz")
continue
elif fizzbuzz % 3 == 0:
print("fizz")
continue
elif fizzbuzz % 5 == 0:
print("buzz")
continue
print(fizzbuzz)

Sample Output:
fizzbuzz
1
2
fizz
4
buzz
fizz
7
8
fizz
buzz
11
fizz
13
14
fizzbuzz
.....

41
fizz
43
44
fizzbuzz
46
47
fizz
49
buzz
Flowchart:

Flowchart: Python program to get Fizz, Buzz and FizzBuzz

@SudhA-2k25
Copy link

FIZZ BUZZ using Function

Multiples of 3 - Fizz

Multiples of 5 - Buzz

def fizzbuzz(n):
result = ["FizzBuzz" if i % 3 == 0 and i % 5 == 0 else "Fizz" if i % 3 == 0 else "Buzz" if i % 5 == 0 else i for i in range(1, n+1)]
return result

Test the fizzbuzz function

n = int(input("Enter the range :"))
output = fizzbuzz(n)
print(output)

@AbhayXcoderx123
Copy link

def fizz_buzz(n):
# Declare a list of strings to store the results
result = []

# Loop from 1 to n
for i in range(1, n + 1):

    # Check if i is divisible by both 3 and 5
    if i % 3 == 0 and i % 5 == 0:

        # Add "FizzBuzz" to the result list
        result.append("FizzBuzz")

    # Check if i is divisible by 3
    elif i % 3 == 0:

        # Add "Fizz" to the result list
        result.append("Fizz")

    # Check if i is divisible by 5
    elif i % 5 == 0:

        # Add "Buzz" to the result list
        result.append("Buzz")
    else:

        # Add the current number as a string to the
        # result list
        result.append(str(i))

# Return the result list
return result

n = 100

Call the fizz_buzz function to get the result

result = fizz_buzz(n)

Print the result

print(' '.join(result))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants