Alternative Constructors

Medium Method Types & Behaviors
Solve in Playground →

Problem Statement

Create a `Date` class with `day`, `month`, `year`. Add a class method `from_string(cls, date_str)` that parses a ‘DD-MM-YYYY’ string and returns a new `Date` instance. Print the date using a `display()` method as ‘Date: DD/MM/YYYY’.

Input Format

A single string 'DD-MM-YYYY'.

Output Format

Print the formatted date string.

Constraints

None

Sample Input

15-08-2026

Sample Output

Date: 15/08/2026

Explanation

Class methods are commonly used in Python as alternative constructors (factories) to create instances from different types of input data.

Starter Code

class Date:
    def __init__(self, day, month, year):
        self.day = day
        self.month = month
        self.year = year
        
    # Define from_string class method here
    
    # Define display method here
    pass

if __name__ == '__main__':
    date_str = input().strip()
    # Create Date using from_string and display
    pass

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used