Python: A class has two methods. First method accept a string from the user, Second method print the string in upper case
Python Class: Exercise-9 with Solution
Write a Python class that has two methods: get_String and print_String , get_String accept a string from the user and print_String prints the string in upper case.
Sample Solution:
Python Code:
class IOString():
def __init__(self):
self.str1 = ""
def get_String(self):
self.str1 = input()
def print_String(self):
print(self.str1.upper())
str1 = IOString()
str1.get_String()
str1.print_String()
Sample Output:
w3resource W3RESOURCE
Pictorial Presentation:
Flowchart:
Python Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Python class to reverse a string word by word.
Next: Write a Python class named Rectangle constructed by a length and width and a method which will compute the area of a rectangle.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://198.211.115.131/python-exercises/class-exercises/python-class-exercise-9.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics