手机
当前位置:查字典教程网 >脚本专栏 >python >使用python实现拉钩网上的FizzBuzzWhizz问题示例
使用python实现拉钩网上的FizzBuzzWhizz问题示例
摘要:最近好多分享这个问题的代码,题目说的是用面向对象或者函数式编程,下面是PYTHON的实现示例复制代码代码如下:#!/usr/bin/pyth...

最近好多分享这个问题的代码,题目说的是用面向对象或者函数式编程,下面是PYTHON的实现示例

复制代码 代码如下:

#!/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()

【使用python实现拉钩网上的FizzBuzzWhizz问题示例】相关文章:

python实现数通设备端口监控示例

使用python解析xml成对应的html示例分享

python实现类似ftp传输文件的网络程序示例

python实现目录树生成示例

python 实现文件的递归拷贝实现代码

python实现博客文章爬虫示例

python实现爬虫下载漫画示例

python实现ip查询示例

python实现socket客户端和服务端简单示例

python抓取网页中的图片示例

精品推荐
分类导航