A Program that prints the numbers from 1 to 100

Steven D'Aprano steve at pearwood.info
Sat Nov 14 20:39:20 EST 2015


On Sun, 15 Nov 2015 04:34 am, Cai Gengyang wrote:

> I want to write a program in Python that does this ----
> 
> "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"."
> 
> How do I go about doing it ?

Start by writing a program that prints the numbers from 1 to 100. Hint:

# Program to print the numbers from 1 to 10.
for i in range(1, 11):
    print(i)


One you get that far, you will need to decide which numbers are multiples of
3, which are multiples of 5, and which are multiples of both 3 and 5. Hint:

# Multiples of 7.
for i in range(1, 11):
    print(i)
    if i % 7 == 0:
        print("multiple of seven")


If you need more help, show us the code you have written.



-- 
Steven




More information about the Python-list mailing list