Write a Python class which has two methods get_String
and print_String
. get_String
should accept a string from the user and print_String
should print the string in upper case.
My Code:
class myClass():
def __init__(self, userInput = input("What is your name? ")):
self.userInput = userInput
def get_string(userInput):
return userInput
def print_string(userInput):
output = userInput.upper()
return output
print(myClass())
Terminal:
What is your name? Anthony
<__main__.myClass object at 0x000001CCDC46BD90>
Should have come out as:
ANTHONY
You seem to be missing the fundamentals re: classes in Python:
get_string
method, not during__init__
.print_string
should print the stored string, it shouldn't require the user to pass a new string.Here is an improved version: