Question

Python Create a function for the Fizz Buzz program (see Assignment01, Q11). The function takes the...

Python

  1. Create a function for the Fizz Buzz program (see Assignment01, Q11). The function takes the following 3 arguments with default values:

    1) max_iteration=100 2) fizz_divider=3
    3) buzz_divider=5

    The function

    • iterates numbers from 1 to max_iteration

    • any number divisible by fizz_divider, “print fizz”

    • Any number divisible by buzz_divider, “print buzz”

    • Any number divisible by fizz_divider and buzz_divider, print “fizz buzz”

    • Otherwise, print the number

0 0
Add a comment Improve this question Transcribed image text
Answer #1

def fizzBuzz(max_iteration=100,fizz_divider=3,buzz_divider=5):

i=1

#starting the loop

while(i<max_iteration):

#checking for fizz division

if(i%fizz_divider==0):

print("fizz",end=" ")

#checking for buzz division

elif(i%buzz_divider==0):

print("buzz",end=" ")

#checking for both

elif(i%fizz_divider==0 and i%buzz_divider==0):

print("fizz buzz",end=" ")

else:

print(i,end=" ")

i=i+1

fizzBuzz(100,2,6)

Add a comment
Know the answer?
Add Answer to:
Python Create a function for the Fizz Buzz program (see Assignment01, Q11). The function takes the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C program that prints the numbers from 1 to 100, but substitutes the word...

    Write a C program that prints the numbers from 1 to 100, but substitutes the word “fizz” if the number is evenly divisble by 3, and “buzz” if the number is divisible by 5, and if divisible by both prints “fizz buzz” like this: 1 2 fizz 4 buzz fizz 7 8 fizz buzz 11 fizz 13 14 fizz buzz 16 17 fizz 19 buzz ... and so on

  • LANGUAGE C++ I need help with all 3 questions. Thank you in advance Password Generator← 10...

    LANGUAGE C++ I need help with all 3 questions. Thank you in advance Password Generator← 10 10.201.51. eRAD D scheduling山UitPro 6 Fizz Buzz Write a function "void FizzBuzz(int n)" that lists all of the numbers from 1 to n, but replace all numbers divisible by 3 but not divizible by 5 with the word "Fizz", replace all numbers divisible by 5 but not divisible by 3 with the word "Buzz", and replace all numbers divisible by both 3 and 5...

  • Python: Using your favorite text editor, write a program that outputs the string representation of numbers...

    Python: Using your favorite text editor, write a program that outputs the string representation of numbers from 1 to n. But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For numbers which are multiples of both three and five output “FizzBuzz”. Submit by uploading a .py file Example: n = 15, Return: [ "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz"...

  • DATA PROGRAMMING: PYTHON Be sure to use sys.argv NOT input. Write a program and create a...

    DATA PROGRAMMING: PYTHON Be sure to use sys.argv NOT input. Write a program and create a function called inch2cm that takes one number in inches as a parameter, converts it to the centimeters and prints the result. The program output is shown below. Input: 14 Output: 14 inches = 35.56 centimeter Write a program and create the following functions: shapes(): takes the shape name and a number as parameters, and calls the proper function to calculate the area. areaCircle(): take...

  • Python: Firstly, create a function and all the work is to be completed as 1 function...

    Python: Firstly, create a function and all the work is to be completed as 1 function inside the function: a loop to run 3 times generating a random number from 1-10 add those 3 numbers together. if the number is greater than or equal 25, print out, the numbers are large numbers else if the number is less than or equal to 5, the sum of the numbers is small and default, the number is average

  • Python: Firstly, create a function and all the work is to be completed as 1 function...

    Python: Firstly, create a function and all the work is to be completed as 1 function inside the function: a loop to run 3 times generating a random number from 1-10 add those 3 numbers together. if the number is greater than or equal 25, print out, the numbers are large numbers else if the number is less than or equal to 5, the sum of the numbers is small and default, the number is average

  • need help with python program The objectives of this lab assignment are as follows: . Input...

    need help with python program The objectives of this lab assignment are as follows: . Input data from user Perform several different calculations Implement conditional logic in loop • Implement logic in functions Output information to user Skills Required To properly complete this assignment, you will need to apply the following skills: . Read string input from the console and convert input to required numeric data-types Understand how to use the Python Modulo Operator Understand the if / elif /...

  • Write a C program that prints the numbers from 1 to 100. But for multiples of...

    Write a C program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

  • CPT 180 Chapter 2 Assignment 3 Directions Using the following guidelines, create a python program. 1....

    CPT 180 Chapter 2 Assignment 3 Directions Using the following guidelines, create a python program. 1. Create a program named printRandomNumbers that gets input from the user and then produces a list of random numbers. 2. Import the random module 3. Add three comment lines at the top of the program that contain: a. Program Name b. Program Description c. Programmer's Name (You) 4. Prompt the user for the following: a. Number of random numbers required b. Lower limit of...

  • Using PYTHON (LOOPS, IF STATEMENTS ) I should write a function buckets that  takes two arguments: (bucketCount,...

    Using PYTHON (LOOPS, IF STATEMENTS ) I should write a function buckets that  takes two arguments: (bucketCount, an integer specifying the number of “buckets” to return and numberLs, a list of numbers ) buckets should split the range of values in numberLs into bucketCount sub-ranges. Specifically buckets should return a list-of-lists of length bucketCount. Each list in the returned list-of-lists represents a “bucket”. Each bucket should contain the numbers from numberLs whose values are greater than or equal to min(numberLs) +...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT