Program to manage a phone store (mobile shop) record using class in Python

Python: Phone store (mobile shop) record management: Here, we are going to implement a Python program to manage Phone store (mobile shop) record using class and object approach.
Submitted by Anuj Singh, on May 06, 2020

Python: Phone store (mobile shop) record management

A smartphone dealer in the locality is very worried about his records as his assistant is not so serious about the overall turnover. He can't change his assistant because he is one from the family and therefore it turns out to be a great problem for Rashid. Rashid discussed this problem with one of his friends and he suggested he use a Computer Program and manage this list of Phones by himself. His friend did a favor and gave him the following python code where he can build a list of smartphones along with their model number and price.

Keypoint

The code and articles are simple but the article focuses on the application part of python programming. How a well-versed person in python can solve a daily life problem. In this article, we focus on building lists. Stay tuned for saving it in txt format.

Python program to manage a phone store (mobile shop) record

# Definig a class Phone, which contain 
# Phone name, model number and price of the Phone

class Phone(object):
    def __init__(self, phnname, model, price):
        self.phnname = phnname
        self.model = model
        self.price = price
    
    def getprice(self):
        return self.price
    
    def getmodel(self):
        return self.model
    
    def __str__(self):
        return self.phnname + ' : ' + str(self.getmodel()) +'  ::'+  str(self.getprice())
  
# Defining a function which generates 
# list of all the Phones    
def prices(rec, phnname, model, price):
    rec.append(Phone(phnname, model, price))
    return rec

# Main Code
Record = []
x = 'y'
while x == 'y':
    phnname = input('Enter the name of the Phone: ')
    height = input('Enter the model number: ')
    model = input('price: ')
    Record = prices(Record, phnname, model, height)
    x = input('Another Phone? y/n: ')
    
# Printing the list of Phone
n = 1
print("---The list of the phone that store have---")
for el in Record:
    print(n,'. ', el)
    n = n + 1

Output

The output of the above program is:

Enter the name of the Phone: iPhone 11
Enter the model number: 7872878277878
price: 64999
Another Phone? y/n: y
Enter the name of the Phone: Galaxy Note 5
Enter the model number: 8787878739
price: 45000
Another Phone? y/n: y
Enter the name of the Phone: Redmi 5 pro
Enter the model number: 326356523265
price: 15999
Another Phone? y/n: n
---The list of the phone that store have---
1 .  iPhone 11 : 64999  ::7872878277878
2 .  Galaxy Note 5 : 45000  ::8787878739
3 .  Redmi 5 pro : 15999  ::326356523265

Python class & object programs »

Related Programs

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.