Python – FizzBuzz Program

Saya kemarin dapat pertanyaan bisa ga bikin program FizzBuzz ?

 

permintaan nya:

kalau ketemu angka 3, tampilkan Fizz

kalau ketemu angka 5, tampilkan Buzz

kalau ketemu 3 dan 5, tampilkan FizzBuzz

 

oke.. berikut code nya di Python:



for i in range(1,100):

    print(i, end = " "),
    if(((i % 3 )== 0) & ((i % 5 ) == 0 )):
        print('fizzbuzz')
    elif((i % 3 )== 0):
        print('fizz')
    elif((i % 5) == 0):
        print('buzz')        
    else:
        print('')        


git: https://github.com/akrisnanda/py-FizzBuzz

 

terimakasih.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *