Write a class User
and then create child classes Admin
, Customer
, Supplier
, each with different permissions. The Admin
should have all permissions, the Customer
can view and buy, and the Supplier
can view and sell. Implement methods to print the permissions.
Example 1: Input:user = Admin()
Output:Permissions: View, Buy, Sell
Example 2: Input:user = Customer()
Output:Permissions: View, Buy
Use inheritance to create child classes and override the method to return the specific permissions for each user type.
class User: def permissions(self): pass class Admin(User): def permissions(self): return "View, Buy, Sell" class Customer(User): def permissions(self): return "View, Buy" class Supplier(User): def permissions(self): return "View, Sell" user = Admin() print(f"Permissions: {user.permissions()}") user = Customer() print(f"Permissions: {user.permissions()}")
Unlock AI & Data Science treasures. Log in!