Example of FizzBuzzWhizz on the Internet using python

Source: Internet
Author: User
This article describes how to use python to implement the FizzBuzzWhizz issue on the internet. For more information, see the code for sharing this issue, this topic is about object-oriented or functional programming. The following is an example of PYTHON implementation.

The code is as follows:


#! /Usr/bin/python
# Encoding: utf8

'''
The Game of "FizzBuzzWhizz"
Author: wang.jiankui89@gmail.com
Mobile: 130-2199-5152
'''
Import sys

Class teacher:
Def _ init _ (self, student_num ):
Self. student_num = student_num

Def gameStart (self, numList ):
For I in range (1, self. student_num + 1 ):
Stu = student (I)
Print stu. answer (numList)

Class student:
Def _ init _ (self, my_num ):
Self. my_num = my_num

Def judgeMod (self, numList ):
ModRes = ""
For num in numList:
If self. my_num % num = 0:
ModRes + = rule [num]
Return modRes if modRes else self. my_num

Def judgeContain (self, first_num ):
ConRes = ""
If str (first_num) in str (self. my_num ):
ConRes = rule [first_num]
Return conRes

Def answer (self, numList ):
ConRes = self. judgeContain (numList [0])
Return conRes if conRes else self. judgeMod (numList)

Def getOps ():
'''Parse options '''
If len (sys. argv )! = 4:
Print "use as fizzBuzzWhizz. py [0-9] [0-9] [0-9]"
Sys. exit ()
Else:
First_num = int (sys. argv [1])
Second_num = int (sys. argv [2])
Third_num = int (sys. argv [3])
Return first_num, second_num, third_num

Def main ():
First_num, second_num, third_num = getOps ()
Global rule
Rule = {first_num: "Fizz", second_num: "Buzz", third_num: "Whizz "}

Student_num = 100

Tea = teacher (100)
Tea. gameStart (first_num, second_num, third_num ))

If _ name _ = "_ main __":
Main ()

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.