Using Python to implement the Fizzbuzzwhizz problem on the hook web _python

Source: Internet
Author: User

Recently a lot of code to share this problem, the topic is the use of object-oriented or functional programming, the following is the implementation of Python examples

Copy Code code 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 percent 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 ()

Related Article

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.