9-3
class User():
def __init__(self,first_name,second_name):
self.first_name=first_name
self.second_name=second_name
def describe_user(self):
print("The current customer is "+self.first_name.title()+" "+self.second_name.title())
def greet_user(self):
print("Hello! "+self.first_name.title()+" "+self.second_name.title())
first_user=User('james','carter')
second_user=User("tom","cruise")
third_user=User("jimmy","short")
first_user.describe_user()
first_user.greet_user()
second_user.describe_user()
second_user.greet_user()
third_user.describe_user()
third_user.greet_user()
9-5
class User():
def __init__(self,first_name,second_name):
self.first_name=first_name
self.second_name=second_name
def describe_user(self):
print("The current customer is "+self.first_name.title()+" "+self.second_name.title())
def greet_user(self):
print("Hello! "+self.first_name.title()+" "+self.second_name.title())
first_user=User('james','carter')
second_user=User("tom","cruise")
third_user=User("jimmy","short")
first_user.describe_user()
first_user.greet_user()
second_user.describe_user()
second_user.greet_user()
third_user.describe_user()
third_user.greet_user()
9-7
class User():
def __init__(self,first_name,second_name):
self.first_name=first_name
self.second_name=second_name
self.login_attempts=0
def describe_user(self):
print("The current customer is "+self.first_name.title()+" "+self.second_name.title())
def greet_user(self):
print("Hello! "+self.first_name.title()+" "+self.second_name.title())
def increment_login_attempts(self):
self.login_attempts+=1
print("The login_attempts value is "+str(self.login_attempts))
def reset_login_attempts(self):
self.login_attempts=0
print("The login_attempts now is "+str(self.login_attempts)+" after reset")
class Admin(User):
def __init__(self,first_name,second_name):
super().__init__(first_name,second_name)
self.privilege=["can add post","can delete post","can ban post"]
def show_privileges(self):
print("The privileges of admin are ")
for i in self.privilege:
print(i)
admin=Admin("James","Short")
admin.show_privileges()
9-12
from admin import Admin
my_admin=Admin("James","Short")
my_admin.show_privileges()
from user import User
class Admin(User):
def __init__(self,first_name,second_name):
super().__init__(first_name,second_name)
self.privilege=["can add post","can delete post","can ban post"]
def show_privileges(self):
print("The privileges of admin are ")
for i in self.privilege:
print(i)
class User():
def __init__(self,first_name,second_name):
self.first_name=first_name
self.second_name=second_name
def describe_user(self):
print("The current customer is "+self.first_name.title()+" "+self.second_name.title())
def greet_user(self):
print("Hello! "+self.first_name.title()+" "+self.second_name.title())
9-13
from collections import OrderedDict
my_dict=OrderedDict()
for i in range(0,5):
key=input()
value=input()
my_dict[key]=value
print(my_dict)