Code Louisville Python programming exercise
Fizz buzz (often spelled FizzBuzz in this context) has been used as an interview screening device for computer programmers. Writing a program to output the first 100 FizzBuzz numbers is a relatively trivial problem requiring little more than a loop and conditional statements. However, its value in coding interviews is to analyze fundamental coding habits that may be indicative of overall coding ingenuity.
From FizzBuzz on wikipedia.org.
In this exercise we will implement the classic programming challenge FizzBuzz. This is the Week 2 Bonus Exercise from the openSAP Learn Python course.If you have already solved it as part of the Learn Python course you can re-use your code here.
Write a Python program that prints the numbers from 1 to 100. If the number is dividable by 3 print Fizz, if the number is dividable by 5 print Buzz instead of the number. If the number is dividable by 3 and 5 print FizzBuzz instead of the number.
Below is the output of the program for the first 15 numbers:
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
- Fork this repo to your account
- Clone your forked repo to your machine
- Write your code in the fizzbuzz.py file
- Optional: test your code on your machine using the automated testing (explained below)
- Add, Commit, and Push your code to GitHub
- Create a Pull Request to merge your code back to the original repo
- Wait for feedback on the Pull Request from a mentor
This repo contains a small testing program that is automatically run by GitHub to validate your code. This testing program is contained in the test_fizz.py file. You don't have to do anything with this file to complete the exercise, but you can follow these steps if you would like to run the tests on your machine.
- Open GitBash in Windows or the Terminal in Mac and navigate to the project folder.
- Install the
pytest
packages. This program uses a python package called pytest. We'll be covering packages later in the course, so for now you can just run the following command without getting into the details of how it works:pip install pytest
. - Run the tests. We won't be covering testing with python in this course. Use
the following command to run the tests:
pytest tests.py
. You can read more about it here. - Review the output from running the test. This will let you know whether your code produces the expected results.