English

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 - Computer Science (Python)

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:

  1. push_Clr(ClrStack, new_Clr): This function takes the stack ClrStack and a new record new_Clr as arguments and pushes this new record onto the stack.
  2. 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".
  3. isEmpty(ClrStack): This function checks whether the stack is empty. If the stack is empty, the function should return True, otherwise the function should return False:
Code Writing
Advertisements

Solution

  1. def push_Clr(ClrStack,new_Clr):
        ClrStack.append(new_Clr)
        print("1 element pushed...")
  2. def pop_Clr(ClrStack):
        if ClrStack==[]:
           print("Underflow")
    else:
         print(ClrStack.pop())
  3. def isEmpty(ClrStack):
        if ClrStack==[]:
           return True
    else:
        return False
shaalaa.com
  Is there an error in this question or solution?
2024-2025 (March) Set 4

APPEARS IN

Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×