/python-functions-practice

Practice functions in Python

Primary LanguagePython

Lab: Practice

No need to turn this in! Instead we will go over as a class together on the whiteboard, so make sure you have working code that you can explain for both problems!

It is recommended to use repl to write and test your code!

It is also recommended to work together with your classmates!

1. Fizzbuzz

Fizzbuzz is often used as a basic way to root out job candidates - often before they ever even reach an interview! So it's to your advantage to be able to do this problem really well!

Prerequesites

  • Writing a function in python
  • Using parameters/arguments in python functions
  • Writing a loop in python
  • Writing conditional statements in python
  • Using modulus
  • Using print to output text

Prompt

Write a function called fizzbuzz that has a parameter n. fizzbuzz takes a numerical argument for the value of n, which is the maximum value to print up to. For example, if I gave you the number 10, I would expect your program to start at 1 and print up to 10.

Additionally, your function should do the following:

  • If a number is divisible by 3, print fizz
  • If a number is divisible by 5, print buzz
  • If a number is divisible by 3 AND 5, print fizzbuzz
  • If none of the above are true, just print the number itself

Example Usage

fizzbuzz(20)

Expected Output

1
2
fizz
4
buzz
fizz
7
8
fizz
buzz
11
fizz
13
14
fizzbuzz
16
17
fizz
19
buzz