Fizz Buzz Question

Source: Internet
Author: User

Title Description: give you an integer n. From 1 to n print each number according to the following rules:

If this number is divisible by 3, print fizz.

If this number is divisible by 5, print buzz.

If this number can be divisible by 3 and 5 at the same time, print fizz buzz.

Example: for example, n = 15, returns an array of strings:

[
"1", "2", "Fizz",
"4", "Buzz", "Fizz",
"7", "8", "Fizz",
"Buzz", "one by One", "Fizz",
"+", "Fizz Buzz"

]


Lintcode The simplest of topics, not to speak, put the code here:

Class solution: "" "    @param n:an integer as Description    @return: A List of strings.    For example, if n = 7, your code should return        ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7"]    "" "    def Fizzbuzz (s  Elf, N):        results = []        for I in range (1, n+1):            if i% = = 0:                results.append ("Fizz Buzz")            elif i% 5 = = 0:                results.append ("Buzz")            elif I% 3 = = 0:                results.append ("fizz")            else:                results.append ( STR (i))        return results


Fizz Buzz Question

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.