Python code question 5

℡╲_俬逩灬. 提交于 2021-01-10 20:05:38

Question: 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.

Hints: Use init method to construct some parameters

#!/usr/bin/env python
# -*- coding:utf-8 -*-
#@Time  : 2021/1/10 18:34
#@Author: developer
#@File  : q5.py

'''

Question: 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.

Hints: Use init method to construct some parameters
'''


class StringTest():
    def __init__(self):
        self.teststring = ''

    def getString(self):
        self.teststring = input("Please input a string:")

    def printString(self):
        print(self.teststring.upper())



string_object = StringTest()
string_object.getString()
string_object.printString()

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!