LoslegenKostenlos loslegen

Changing programming paradigms

As sometimes happens, you've started out on a project using one paradigm and now realized that it wasn't quite the right one for the task. You've currently got a simple procedural program for storing automobile sales information that is going to need to be converted to an object-oriented program so that it can be extended more easily.

Diese Übung ist Teil des Kurses

Programming Paradigm Concepts

Kurs anzeigen

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Old procedural code
def buy_car(budget, price):
    if budget > price:
        print("You can buy this car!")
    else:
        print("This car is too expensive for now.")

# Define the Car class
____ Car():
    # Initialize each car with a price
    def __init__(____, price):
        self.price = ____
Code bearbeiten und ausführen