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? :)

50 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
  19. very helpfull blog it was a pleasure reading your blog
    would love to read it more
    knowldege is not found but earned through hardwork and good teaching
    that being said click here to join us the next best thing in bangalore
    devops online training
    Devops Training in Bangalore

    ReplyDelete
  20. Your blog was very interesting & easy to understand. Thank you so much sharing that valuable blog.. Internal Audit | Vendor Reconciliation | Fixed Assets Audit


    ReplyDelete


  21. Those guidelines additionally worked to become a good way to recognize that other people online have the identical fervor like mine to grasp great deal more around this condition.

    Selenium Training in Chennai

    Aws Training in Chennai

    ReplyDelete
  22. Hi Man,


    I love all the posts, I really enjoyed.
    I would like more information about this, because it is very nice., Thanks for sharing.

    First off I'm not a strong Python developer. I'm a Network Engineer and I use Python to create automation scripts for accessing routers and switches. I've never tried to convert a script of any type. A coworker asked me to help him convert a Perl script to Python. In my research and findings, I'm having some issues trying to find what I need in Python or even making it work.

    The Perl script accesses Cisco's Call Manager (phone system) webpage (https, authenication, ignore SSL), it pulls data off the pages, may be more than one with up to 2000 line items on each page. It then parses it (XML) into two columns, userID and extensions, and dumps it into a .CSV file. It then reads that .CSV file, accesses Microsoft Active Directory, looks up the userID and puts the extension of that userID into the persons Active Directory profile under the ipPhone attribute.

    The modules the Perl script uses are below vs what I've been trying to use in Python3...

    Net::LDAP; = python3-ldap3
    LWP::UserAgent; = urllib3
    LWP::Protocol::https; = requests
    XML::Simple; = lxml

    Any help would be appreciated. I'd like to know if I'm using the right equivalents of Python3 and any great examples on how to use these modules.

    So far,
    just even getting
    Python3 to "get" the URL, pass authentication credentials on the website and to ignore SSL cert has been really hard and frustrating. I'm not getting anywhere with that.

    THANK YOU!! This saved my butt today, I’m immensely grateful.


    Obrigado,

    Ajeeth kapoor

    ReplyDelete
  23. Nice blog. Thank you for sharing. The information you shared is very effective for learners I have got some important suggestions from it. Duplicate Payment Review | Continuous Transaction Monitoring | Duplicate Payment Recovery

    ReplyDelete
  24. 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.

    https://www.besanttechnologies.com/robotic-process-automation-rpa-training-in-bangalore

    ReplyDelete
  25. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
    Python Training in Bangalore

    ReplyDelete
  26. And indeed, I’m just always astounded concerning the remarkable things served by you. Some four facts on this page are undeniably the most effective I’ve had. Best AWS Training in Bangalore

    ReplyDelete
  27. Those guidelines additionally worked to become a good way to recognize that other people online have the identical fervor like mine to grasp great deal more around this condition.

    Best AWS training in bangalore

    ReplyDelete
  28. Hi Your Blog is very nice!!

    Get All Top Interview Questions and answers PHP, Magento, laravel,Java, Dot Net, Database, Sql, Mysql, Oracle, Angularjs, Vue Js, Express js, React Js,
    Hadoop, Apache spark, Apache Scala, Tensorflow.

    Mysql Interview Questions for Experienced
    php interview questions for freshers
    php interview questions for experienced
    python interview questions for freshers
    tally interview questions and answers

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

    ReplyDelete
  30. It's A Great Pleasure reading your Article, learned a lot of new things, we have to keep on updating it Mulesoft certification training Thanks for posting.

    ReplyDelete