|  | 
 
| 
看到一个100题, 第5题 我就不会做了,答案也看不明白
x
马上注册,结交更多好友,享用更多功能^_^您需要 登录 才可以下载或查看,没有账号?立即注册  题目是
 Define a class which has at least two methods:
 
 getString: to get a string from console input
 printString: to print the string in upper case.
 Also please include simple test function to test the class methods.
 
 
 答案是:
 class IOstring():
 def get_string(self):
 self.s = input()
 
 def print_string(self):
 print(self.s.upper())
 
 xx = IOstring()
 xx.get_string()
 xx.print_string()
 
 没看懂 ,能不能一句一句讲讲 。谢谢
 
 还有其他答案么?
 
 我这么写 报错啊 为什么
 
 
 x=(str)
 def get_string(self,a):
 a=input('enter your string:')
 print(a)
 def print_string():
 print(a.get_string.uper)
 
 x.get_string()
 
 
 
 
复制代码class IOstring(): #定义类IOstring
    def get_string(self): #定义方法get_string
        self.s = input() #从控制台获取字符串s
    def print_string(self): #定义方法print_string
        print(self.s.upper()) #以大写方式输出s
xx = IOstring() #实例化对象xx
xx.get_string() #xx获取字符串s
xx.print_string() #xx以大写方式输出s
 | 
 |