第1关类的声明与定义
第2关类的属性与实例化
第3关绑定与方法调用
第4关静态方法与类方法
第5关类的导入
1
# 请在下面填入定义Book类的代码
#********** Begin *********#
class Book():
#********** End *********#
# '书籍类'
def __init__(self,name,author,data,version):
self.name = name
self.author = author
self.data = data
self.version = version
def sell(self,bookName,price):
print("%s的销售价格为%d" %(bookName,price))
2
class People:
# 请在下面填入声明两个变量名分别为name和country的字符串变量的代码
#********** Begin *********#
name = ''
country = ''
#********** End **********#
def introduce(self,name,country):
self.name = name
self.country = country
print("%s来自%s" %(name,country))
name = input()
country = input()
# 请在下面填入对类People进行实例化的代码,对象为p
#********** Begin *********#
p = People()
#********** End **********#
p.introduce(name,country)
3
import fractionSumtest
# 请在下面填入创建fractionSum的实例fs的代码
#********** Begin *********#
fs = fractionSumtest.fractionSum()
#********** End **********#
n = int(input())
if n % 2 == 0:
# 请在下面填入调用fractionSumtest类中dcall方法的代码,计算当n为偶数时计算的和
#********** Begin *********#
sum = fs.peven(n)
#********** End **********#
else:
# 请在下面填入调用fractionSumtest类中dcall方法的代码,计算当n为奇数时计算的和
#********** Begin *********#
sum = fs.podd(n)
#********** End **********#
print(sum)
4
class BookSell:
static_var = 100
def sell(self,name,author,version,price):
print("%s的销售价格为%d" %(name,int(price)))
# 请在下面填入函数修饰符将printStatic()方法声明为静态方法
#********** Begin *********#
@staticmethod
#********** End **********#
def printStatic():
print(BookSell.static_var)
# 请在下面填入函数修饰符将printVersion(cls)方法声明为类方法
#********** Begin *********#
@classmethod
#********** End **********#
def printVersion(cls):
print(cls)
5
# 请在下面输入调用DataChange模块中eightToten(self,p)的代码,以实现将输入的八进制转换成十进制输出
#********** Begin *********#
from DataChangetest import DataChange
n = input()
c = DataChange()
c.eightToten(n)
#********** End **********#