2个回答
展开全部
一个用字符展示表情的类,传入参数次数,可使用方法smile, dizzy, peace, greedy, nerd
这个里面代码都没空格,请自行加空格或分隔符
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
class code_emoji():
def __init__(self, n):
self.number = n
self.code = [94, 95, 118, 62, 60, 39, 36]
def __str__(self):
return 'this is just a code emoji class!'
def __order(self, func):
func = getattr(func, '__name__')
if func == "smile":
return [self.code[0], self.code[1], self.code[0]]
elif func == "peace":
return [self.code[2], self.code[1], self.code[2]]
elif func == "dizzy":
return [self.code[3], self.code[1], self.code[4]]
elif func == "greedy":
return [self.code[-1], self.code[1], self.code[-1]]
elif func == "nerd":
return [self.code[-2], self.code[1], self.code[-2]]
def smile(self):
print "\n笑脸"
for i in xrange(self.number):
print "".join([chr(i) for i in self.__order(self.smile)])
def dizzy(self):
print "\n晕"
for i in xrange(self.number):
print "".join([chr(i) for i in self.__order(self.dizzy)])
def peace(self):
print "\n平静"
for i in xrange(self.number):
print "".join([chr(i) for i in self.__order(self.peace)])
def greedy(self):
print "\n贪婪"
for i in xrange(self.number):
print "".join([chr(i) for i in self.__order(self.greedy)])
def nerd(self):
print "\n毫无波动"
for i in xrange(self.number):
print "".join([chr(i) for i in self.__order(self.nerd)])
if __name__ == '__main__':
a = code_emoji(2)
a.smile()
a.dizzy()
a.peace()
a.greedy()
a.nerd()
程序运行结果:
C:\Python27\python.exe G:/windows_code/python/threat/just_test.py
笑脸
^_^
^_^
晕
>_<
>_<
平静
v_v
v_v
贪婪
$_$
$_$
毫无波动
'_'
'_'
Process finished with exit code 0
这个里面代码都没空格,请自行加空格或分隔符
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
class code_emoji():
def __init__(self, n):
self.number = n
self.code = [94, 95, 118, 62, 60, 39, 36]
def __str__(self):
return 'this is just a code emoji class!'
def __order(self, func):
func = getattr(func, '__name__')
if func == "smile":
return [self.code[0], self.code[1], self.code[0]]
elif func == "peace":
return [self.code[2], self.code[1], self.code[2]]
elif func == "dizzy":
return [self.code[3], self.code[1], self.code[4]]
elif func == "greedy":
return [self.code[-1], self.code[1], self.code[-1]]
elif func == "nerd":
return [self.code[-2], self.code[1], self.code[-2]]
def smile(self):
print "\n笑脸"
for i in xrange(self.number):
print "".join([chr(i) for i in self.__order(self.smile)])
def dizzy(self):
print "\n晕"
for i in xrange(self.number):
print "".join([chr(i) for i in self.__order(self.dizzy)])
def peace(self):
print "\n平静"
for i in xrange(self.number):
print "".join([chr(i) for i in self.__order(self.peace)])
def greedy(self):
print "\n贪婪"
for i in xrange(self.number):
print "".join([chr(i) for i in self.__order(self.greedy)])
def nerd(self):
print "\n毫无波动"
for i in xrange(self.number):
print "".join([chr(i) for i in self.__order(self.nerd)])
if __name__ == '__main__':
a = code_emoji(2)
a.smile()
a.dizzy()
a.peace()
a.greedy()
a.nerd()
程序运行结果:
C:\Python27\python.exe G:/windows_code/python/threat/just_test.py
笑脸
^_^
^_^
晕
>_<
>_<
平静
v_v
v_v
贪婪
$_$
$_$
毫无波动
'_'
'_'
Process finished with exit code 0
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询