Python FizzBuzzWhizz (checklist) Example

Source: Internet
Author: User
This article mainly introduces the example of FizzBuzzWhizz in python. If you need a FizzBuzzWhizz question, you can refer to the following questions.

1. You must first specify three different special numbers, which must be single digits, such as 3, 5, and 7.
2. Let all the students form a team and report the number in sequence.
3. when a student reports a number, if the number is a multiple of the first Special Number (3), it cannot be said, rather than Fizz; if the number is the second special number (5) buzz. If the number is a multiple of the third special number (7), Whizz is used.
4. when a student reports a number, if the number is a multiple of two special numbers at the same time, special processing is also required, such as the first Special number and the second special number, the number cannot be said, but FizzBuzz, and so on. If it is a multiple of three special numbers, FizzBuzzWhizz should be used.
5. when a student reports a number, if the number contains the first special number, the number cannot be used, but the corresponding word is used. For example, the First Special number in this example is 3, so the student who needs to report the message 13 should say Fizz. If the number contains the first special number, rule 3 and rule 4 are ignored. For example, if you want to report to 35, only Fizz is reported, but BuzzWhizz is not reported.

Now, we need you to complete a program to simulate this game. It first accepts three special numbers and then outputs the numbers or words that 100 students should report.

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 :'))
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 for I in range (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.