so here i'm trying to make a simple library that user can add and remove books from his shopping cart, but idon't know how to use if function with oop and classes
try:
class library:
def __init__(self, books, costumer):
self.books = books
self.costumer = costumer
# sign:
check = input("manager account(1),costumer account(2): ")
if check == "2":
#age >= 18
age = int(input("enter your age: "))
if age >= 18:
#name
name = input("enter your firstname: ")
# ID
import random
x = "ID"+str(random.randint(101,999))
print(f"your ID is: {x}")
print("you should memorize it")
y = input("enter password that has at list 8 caracterse: ")
# Password
while len(y) < 8:
y = input("enter password that has at list 8 caracterse: ")
print(f"your password is: {y}")
print("you should memorize it")
data = [x,y]
choice_1 = input("check your shopping cart(1): \nadd books to your shopping cart(2): \nremove books from your shopping cart(3): ")
if choice_1 == "1":
def __str__(self):
return f"costumer {self.costumer} bought those books{self.books}"
elif choice_1 == "2":
def __iadd__(self, other):
self.books.append(other)
return self
order = library(["the golsen company"],"Mr.asad")
print(order.books)
order += input("enter a book: ")
print(order.books)
except ValueError as ages:
print(ages)
i don't know if this is the right way to use if function with classes so if you can just give me an exampl to show me how to use if function with classes
Aucun commentaire:
Enregistrer un commentaire