I wrote a fizz buzz variation method in Python which prints "fizz", "bang", and "buzz" for 3, 7, and 11 respectively.
def FizzBang():
string = ''
for n in range(1,101):
msg = ""
if not n % 3:
msg += "Fizz"
if not n % 7:
msg += "Bang"
if not n % 11:
msg += "Buzz"
print msg or str(n)
What can I do to increase the speed of this program? I know the modulus is quite expensive. Also maybe concatenating strings might not be needed as well.