We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. FizzBuzz
  2. Discussions

FizzBuzz

Problem
Submissions
Leaderboard
Discussions

    You are viewing a single comment's thread. Return to all comments →

  • dat0user
    5 years ago+ 2 comments

    I got 6.9 for this in python 3:

    for x in range(1,101):
     if x%3==0 and x%5==0:print("FizzBuzz")
     elif x%3==0:print("Fizz")
     elif x%5==0:print("Buzz")
     else:print(x)
    

    Did i do good for someone that has been learning python for a week?

    Edit:: Changed it up a little, now my score is 7.9::

    for x in range(1,101):
     if x%15==0:print("FizzBuzz")
     elif x%3==0:print("Fizz")
     elif x%5==0:print("Buzz")
     else:print(x)
    

    Edit:: EVEN BETTER! 9.6!

    a="Fizz"
    b="Buzz"
    for x in range(1,101):
        print(a+b if x%15==0 else a if x%3==0 else b if x%5==0 else x)
    

    9.7:

    for x in range(1,101):
     print("FizzBuzz" if x%15==0 else "Fizz" if x%3==0 else "Buzz" if x%5==0 else x)
    

    This'll probably be my last, 13.6::

    for(x)in range(1,101):print("Fizz"*(x%3==0)+(x%5==0)*"Buzz"or x)
    
    6|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy