目录
第一关 类的声明与定义
# 请在下面填入定义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))
第二关 类的属性与实例化
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)
第三关 绑定与方法调用
import fractionSumtest
# 请在下面填入创建fractionSum的实例fs的代码
########## Begin ##########
fs = fractionSumtest.fractionSum()
########## End ##########
n = int(input())
if n % 2 == 0:
# 请在下面填入调用fractionSumtest类中dcall方法的代码,计算当n为偶数时计算的和
########## Begin ##########
sum = fs.dcall(fs.peven,n)
########## End ##########
else:
# 请在下面填入调用fractionSumtest类中dcall方法的代码,计算当n为奇数时计算的和
########## Begin ##########
sum = fs.dcall(fs.podd,n)
########## End ##########
print(sum)
第四关 静态方法与类方法
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)
第五关 类的导入
# 从 DataChangetest 模块中导入 DataChange 类,并使用该类中的 eightToten(self,p) 方法,实现将输入的八进制转换成十进制输出。
########## Begin ##########
p = input()
from DataChangetest import DataChange
a = DataChange()
a.eightToten(p)
########## End ##########