Skip to content

Instantly share code, notes, and snippets.

@Praneeth313
Created May 13, 2021 10:54
Show Gist options
  • Save Praneeth313/0c0273698d8125610d29f1d556a43b6b to your computer and use it in GitHub Desktop.
Save Praneeth313/0c0273698d8125610d29f1d556a43b6b to your computer and use it in GitHub Desktop.
Pirple - Python is Easy : Assignment #5: Basic Loops
Write a 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".
"""
'''
Created a list using range function with elemnts as numbers from 1 to 100
'''
Numbers = list(range(1,101))
'''
Created a for loop with nested if statements
'''
for i in Numbers:
if i%3 == 0:
'''
if the number is the divisible by 3 then replace the number with 'Fizz'
by subracting the number with 1 and using it as index
'''
Numbers[i-1] = "Fizz"
if i%5 == 0:
'''
if the number is the divisible by 5 then replace the number with 'Buzz'
by subracting the number with 1 and using it as index
'''
Numbers[i-1] = "Buzz"
if i%3 == 0 and i%5 == 0:
'''
if the number is the divisible by 3 and 5 then replace the number with 'FizzBuzz'
by subracting the number with 1 and using it as index
'''
Numbers[i-1] = "FizzBuzz"
'''
Use a for loop to go through all the elements of the List and print them
'''
for n in Numbers:
print(n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment