Skip to main content

Posts

#Object Oriented Programming  (Python) #SIMPLE PROFIT CALCULATOR   --  StudySourceCodes.blogspot.com class Sales: def __init__(self, prodName,costPrice,sellingPrice): self.prodName = prodName self.costPrice = costPrice self.sellingPrice = sellingPrice #Getting coat price def get_costPrice(self): return self.costPrice #Getting selling price def get_sellingPrice(self): return self.sellingPrice class Product: def __init__(self,prodCat,max_prods): self.prodCat = prodCat self.max_prods = max_prods self.products = [] #Adding products to a list def add_prods(self,product): if len(self.products) < self.max_prods: self.products.append(product) print("Product successfully added!\n\n") else: print("Oops! This product has reached maximum number of products!") #Calculating total profit def get_tot_profit(self): tot_profit = 0 for product in self.products: profit = product.get_sellingPri
Recent posts

User Creation and Login System in Python

The program below does two things: 1.  It allows a user to login if he or she already has an account on the system. 2.  It allows a user to create an account and login afterwards if the user does not have an account already (New user) in the system. NOTE : The program allows the user only two chances in every action. If the user fails again in the second chance, the program denies access from the user. Try it to find out. It's fun... You can copy and paste in your development environment and study how the code works  or type it out yourself. Either way, you are good to go. To login as an existing user use the details below: Username:  studysourcecodes Password:  python The program starts below: userDict = {"studysourcecodes":"python"} #Note:  Username = Dictionary 'key' #            Password = Dictionary 'value' result = "" result1 = "" result2 = "" result3 = "" result4 = &qu

How to insert data into MySQL database table

To insert, save or add data to database table we use the insert statement which is shown below. INSERT INTO table_name VALUES (list of values separated by commas).  See the query below for more details. The query below will insert data into all the columns in the products table we created in the previous tutorial . INSERT INTO products VALUES ("PI001","TELEVISION", "LG", 50000, 3, "2020-01-11", "2020-01-12") Congratulations! You just inserted your a record into your database. What the query does is: it tells the system to go our database and look for a table named products (as there could be more than one table in a database) and INSERT all the VALUES (our products information) listed in the bracket INTO it. NOTE :           The use of double quotes and commas around the values inside the bracket. The comma is used to separate each value from the next one while the double quote is used to

Getting Started With Python Programming - What you need to know.

Python is a general purpose programming language developed by a Dutch programmer Guido Van Rossum, and have been in existence since 1991. It is a very friendly language, and so a good choice for those looking out to kick off their programming career. What can you do with python? Web development Desktop application development Data science (data visualization and machine learning) Python IDEs : IDE which stands for  Integrated Development Environment is an interface where programmers can write and execute their codes.  Python IDEs include but not limited to: Jupyter, Atom, Pycharm, Thonny, IDLE, Spyder, Pydev and Pydroid. Python frameworks and their uses Django - used for web development Flask - also used for web development Cherrypy - for web applications Web2py - for web applications Turbogears - for web applications CubicWeb - for web applications Python libraries These mostly come already embedded in python IDEs and requires no special installatio

How To Create a Table In MySQL Database

A table in SQL is simply a collection of data in columns and rows. It forms a very important part of a database as it holds all the information in it. In this tutorial we will create a table that contains seven columns which will store product information (record) like product id, product name, manufacturer, price, quantity, purchase date and entry date.  To create a table in MySql database we use the create table syntax shown below. CREATE TABLE products ( product_id CHAR(6) PRIMARY KEY, product_name VARCHAR(100) NULL, manufacturer varchar(100), price INT NOT NULL, quantity int NOT NULL, purchase_date DATE, entry_date DATETIME ) Understanding the create table syntax above create table is a statement used in creating tables sales_record is our chosen name for the table item_id, item_name, quantity, price, date_sold and entry_date form the columns of our table. Notice the use of underscore to bind column names that contained more than one word. Anothe

How to make GUI dictionary in python

In application development, a dictionary  is an application that helps us with the meaning of a word by simply typing the word in a provided input box and clicking a button. Follow the steps below to get started. 1.   IMPORT THE NECESSARY MODULES AND LIBRARIES To be able to develop this application successfully, we need to first of all import the Tkinter module as shown in the coloured text below. Note, Tkinter comes already embedded in most python IDEs like Jupyter Notebook and Pycharm so requires no special installation. from tkinter import * Then import MessageBox . MessageBox as the name sounds helps us to display messages as popup in the event of an error or success or whatever you wish in your code. The syntax for importing the MessageBox is shown below. from tkinter import messagebox as MessageBox 2.  CREATE AND FORMAT A WINDOW (CONTAINER) FOR THE PROJECT window = Tk()  window.geometry("535x360")  window.title('Dictionary - StudySourceC