Python complete fizzbuzzwhizz problem (Hook net interview question) example

Source: Internet
Author: User
Pull Hook Mesh question

1. You first say three different special numbers, the requirements must be single-digit, such as 3, 5, 7.
2. Make a team of all the students and then count off the order.
3. When the student counts off, if the quoted figure is a multiple of the first special number (3), then the number should not be said, but fizz; if the quoted figure is a multiple of the second special number (5), then buzz; if the quoted number is a multiple of the third special number (7), say whizz.
4. When a student counts off, if the quoted number is also a multiple of two special numbers, also special treatment, such as the first special number and the second special number of multiples, then can not say the number, but to say Fizzbuzz, and so on. If it is also a multiple of three special numbers, say fizzbuzzwhizz.
5. When the student counts off, if the quoted number contains the first special number, then can not say the number, but to say the corresponding words, such as the first special number in this case is 3, then to report 13 of the students should say fizz. If the number contains the first special number, then ignore rules 3 and rule 4, for example, to report 35 of the students only reported fizz, do not report buzzwhizz.

Now, we need you to complete a program to simulate this game, it first accepts 3 special numbers, and then outputs 100 students should count off the number or word.

The code is as follows:


def check (A, DIC, D):
Answer = ' '
If Str (a) in Str (d):
return Dic[a]
For x in DIC:
If not (d% x):
Answer = answer + dic[x]
If not answer:
Return D
Return answer

if __name__ = = ' __main__ ':
a = Int (raw_input (' Input u A: '))
b = Int (raw_input (' Input u B: '))
c = Int (raw_input (' Input u c: '))
DIC = {A: ' Fizz ', B: ' Buzz ', C: ' Whizz '}
For x in Xrange (1, 101):
Print Check (A, dic, X)

The code is as follows:


[' Fizz ' [(str (3) not in Str (i)] *4:]or ' Fizz ' [I% 3 * 5:] + ' Buzz ' [I% 5 * 5:] + ' whizz ' [I% 7 * 5:] or I-I in rang E (1,101)]

  • 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.