Wednesday, April 16, 2014

Python Developer Interview Questions: Fizz-Buzz

Fizz-buzz is a very basic interview question mainly asked to see if a developer/programmer can actually code or not. Nothing too sophisticated.I was asked to code a FizzBuzz today for the second time in my life and I thought why not to blog about it, since it seems to be getting popular to ask from developers. To make it a bit challenging for myself, I coded it in Python, since I have the least skill in coding Python, although I think it is a sexy language.

Interview Question: 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”."

Solution:
__author__ = 'amir'

for x in range(1, 100):
    if x % 15 == 0:
        print 'fizzbuzz'
    elif x % 3 == 0:
        print 'fizz'
    elif x % 5 == 0:
        print 'buzz'
    else:
        print x

Remark: Just remember that a number that is both divisible by three and five is also divisible by 15. Another note is that you need to check if the divisible by 15 condition first of all, if not they end up in divisible by 3 and 5 condition. Makes sense, right? :)

32 comments:

  1. This blog awesome and i learn a lot about programming from here.The best thing about this blog is that you doing from beginning to experts level.

    Love from

    ReplyDelete
  2. Wow. This really made my day. Thanks a lot!
    JQuery Training JQuery Training Javascript JQuery Online Training

    JQuery Online Training JQuery Online Training Javascript Online Training JQuery Training

    JavaScript Training Courses

    ReplyDelete
  3. Such a great articles in my carrier, It's wonderful commands like easiest understand words of knowledge in information's.
    Python Training in Chennai

    ReplyDelete
  4. Thank you very much, nice article to learn and it gives clear picture.
    Java Script training in chennai

    ReplyDelete
  5. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Android Training in Chennai
    Ios Training in Chennai

    ReplyDelete
  6. Python Training in Chennai with real-time corporate professionals. We are providing practical oriented best python training institute in Bangalore. Python Training in Bangalore |
    Pearson Vue Exam Center in Bangalore

    ReplyDelete
  7. Thanks for one marvelous posting! I enjoyed reading it; you are a great author. Besant technology provides python course training in chennai

    ReplyDelete
  8. I simply wanted to thank you so much again. I am not sure the things that I might have gone through without the type of hints revealed by you regarding that situation.

    Java Training in Bangalore|

    ReplyDelete
  9. It’s always so sweet and also full of a lot of fun for me personally and my office colleagues to search your blog a minimum of thrice in a week to see the new guidance you have got.

    Selenium Training in Bangalore

    ReplyDelete
  10. Thanks for one marvelous posting! I enjoyed reading it; you are a great author. I will make sure to bookmark your blog and may come back someday. I want to encourage that you continue your great posts, have a nice weekend!
    DevOps Training in Bangalore

    ReplyDelete
  11. Thanks a lot very much for the high quality and results-oriented help. I won’t think twice to endorse your blog post to anybody who wants and needs support about this area.

    Hadoop training in bangalore

    ReplyDelete
  12. Day by day I am getting new things and learn new concept through your blogs, I am feeling so confidants, and thanks for your informative blog keep your post as updated one... AWS Training in Bangalore

    ReplyDelete
  13. Very Nice Blog on Python Developer Interview Questions,
    Thank you for sharing kindly keep writing more about Python
    Thank you once again.
    Devops Training in Bangalore

    ReplyDelete
  14. This comment has been removed by the author.

    ReplyDelete
  15. This comment has been removed by the author.

    ReplyDelete
  16. the blog is about Python Developer Interview Questions for more updates on python follow the link

    Python Online Training

    For more info on other technologies go with below links

    tableau online training hyderabad

    ServiceNow Online Training

    mulesoft Online Training

    ReplyDelete
  17. This information is informative. Thanks for taking time to discuss this. QA Training Hub is best Python Programing Online Training Center in India. Python Online Training provided by real time working Professional Mr. Dinesh. Data Scientist and RPA Expert with 18+ years of industry experience in teaching Python. Best Python Online Training Contact: Mr. Dinesh Raju : India: +91-8977262627, USA: : +1-845-493-5018, Mail: info@qatraininghub.com

    ReplyDelete
  18. the blog is about Python Developer Interview #Python it is useful for students and Python Developers for more updates on python follow the link

    Python Online Training Bangalore

    For more info on other technologies go with below links

    tableau online training hyderabad

    ServiceNow Online Training

    mulesoft Online Training

    ReplyDelete