Python Exercise 5 Problem
In this Python exercise, write a Python program that can define a class with a minimum of two methods. Have a user provide input via prompt and then print that input in uppercase in the second method. The input can be anything, but the second method must take the input and make the first method input in all uppercase with a print statement.
Python Exercise 5 Solution
Python Code Input:
1 2 3 4 5 6 7 8 9 10 11 12 13 | class UserInput(object): def __init__(self): self.color = "" def getColor(self): self.color = input("What is your favorite color? ") def printColor(self): print(f"Your favorite color is {self.color.upper()}. ") colorObj = UserInput() colorObj.getColor() colorObj.printColor() |
User Input:
1 | What is your favorite color? red |
Python Code Output:
1 | Your favorite color is RED. |