Advertisements
Advertisements
Question
A stack, named ClrStack, contains records of some colors. Each record is represented as a tuple containing four elements - ColorName, RED, GREEN, BLUE. ColorName is a string, and RED, GREEN, BLUE are integers. For example, a record in the stack may be (‘Yellow’, 237, 250, 68)
Write the following user-defined functions in Python to perform the specified operations on ClrStack:
push_Clr(ClrStack, new_Clr):This function takes the stack ClrStack and a new recordnew_Clras arguments and pushes this new record onto the stack.pop_Clr(ClrStack):This function pops the topmost record from the stack and returns it. If the stack is already empty, the function should display the message“Underflow".isEmpty(ClrStack):This function checks whether the stack is empty. If the stack is empty, the function should returnTrue, otherwise the function should returnFalse:
Code Writing
Advertisements
Solution
-
def push_Clr(ClrStack,new_Clr): ClrStack.append(new_Clr) print("1 element pushed...") -
def pop_Clr(ClrStack): if ClrStack==[]: print("Underflow") else: print(ClrStack.pop()) -
def isEmpty(ClrStack): if ClrStack==[]: return True else: return False
shaalaa.com
Is there an error in this question or solution?
