Tạo ra kiểu dữ liệu mới

Blog của Chiến

Trở về Mục lục cuốn sách

Các ngôn ngữ lập trình hướng đối tượng cho phép lập trình viên tạo nên những kiểu dữ liệu biểu hiện giống như những kiểu dữ liệu lập sẵn. Ta sẽ khám phá khả năng này bằng cách lập nên một lớp Fraction hoạt động rất giống với những kiểu dữ liệu số có sẵn như số nguyên, số nguyên dài và dạng dấu phẩy động.

Các phân số, còn gọi là số hữu tỉ, là những giá trị có thể được biểu diễn bằng tỉ số giữa hai số nguyên, như 5/6. Số ở trên được gọi là tử số còn số ở dưới là mẫu số.

Ta bắt đầu bằng việc định nghĩa một lớp Fraction với một phương thức khởi tạo để cung cấp các số nguyên là tử số và mẫu số:

View original post 1,779 more words

Advertisements

Introduction to Python GUI Programming with PyQt and Qt Designer

bytes and pieces

PyQt is a popular Python binding for the cross-platform C++ application framework, Qt. Qt Designer allows for drag-and-drop Python GUI building. This tutorial will cover how to make a basic calculator app to find the distance between two points.

I will be working with Python 3.4 and PyQt5 in this tutorial. If you are using Windows I recommend downloading the WinPython software package which includes Qt Designer, Spyder (a scientific programming IDE), the IPython console, and many integrated libraries such as NumPy, SymPy, and Matplotlib. This software package is free, portable, and very easy to use.

Get started by opening up Qt Designer, clicking ‘New’, and selecting the ‘Main Window’ option. The left side of the screen features a list of built-in widgets that can be added to your GUI. The following widgets will be used in this tutorial:

QGroupBox: group box container with a title

QLabel: a…

View original post 496 more words

Making a Facebook Messenger Bot

Harry's Compsci Blog

Messaging bots are supposedly the future, with some people going as far as to say that apps will be replaced by bots or other interfaces inside messaging apps. While I disagree with this statement, I do think there are entire categories of apps that will become extinct in the near future due to bots. In this post I’ll walk through the process of creating a simple bot for Facebook messenger. You’ll need a Facebook account and a Heroku account.

The first time I made a bot I followed this guide, which uses Node.js. I will refer back to this guide during this post for the steps involved in making the Facebook page and using the Facebook developer dashboard.

The core idea of the bot we’re making is one that gets sent single-variable equations and promptly responds with the solutions. The first thing we’ll need to think about is the…

View original post 1,595 more words

Tkinter Part 1

Programming Ideas

Tkinter Part 1

I will be posting a series of twelve articles on using the Python, Tkinter Graphical User Interface Manager to generate windows. Tkinter is one of several Tk GUI managers for Python. Others like wxPython, PyQt, PyGTK, and JPython and several others exist and are also used. These notes only apply to Tkinter.

Every lesson has code examples of exactly how the control is used and the resulting window the code will produce. There are many different ways to code the same example. I use my way of coding for the examples. I expect you to try others as you uncover them. The last three articles will be example programs that use several of the controls on a window to show how they interact within a program. All of the examples were created on a MacBook Air running OS/X Version 10.11.6, El Capitan, but Python may also be…

View original post 886 more words

NodeMCU and light detector – part 3: PyQt5 to the rescue

Raspi Playground

Our previous computer app was a failure. Happens from time to time:) Choosing wxPython was a huge mistake. Seems wx bindings are outdated.
After a long walk to cool of my head and think a little (but mostly catching pokemons) I recovered my strength and began second approach. This time I’m using PyQt5. It has Python3 bindings and lots of nice features, like ability to emit signals to other objects.

Spoiler: this time a full success 🙂

Get source from GitHub

View original post 359 more words

Building an AI Bot

TechSight

In this post I discuss the work that I did as part of a project to develop a TicTacToe playing AI bot.  As part of the project, a python GUI was developed that allowed a user to play against the bot as well as to train the bot.

The Interface

This was my first time developing a GUI and since the underlying AI code was based on Python, I decided to use Python for the GUI development as well.

When it comes to GUI development, there are two main packages i. Tkinter (default package, comes installed with Python) and ii. wxPython. There are a lot of discussions online on which is the better of the two [linklink], but the best resource that I found was a side-by-side comparison of the steps involved in building a basic GUI using both Tkinter and wxPython [link]. After…

View original post 2,040 more words

Khoảng cách trong mặt phẳng tọa độ (1)

Nguyen Trung Tuan

Bài 1. Tam giác $latex ABC$ có $latex AB:x-y+4=0,BC:3x+5y+4=0$ và $latex CA:7x+y-12=0$. Hỏi $latex O$ nằm trong hay ngoài tam giác?

Bài 2. Cho $latex M(1;4),N(6;2)$. Lập phương trình đường thẳng qua $latex M$ sao cho khoảng cách từ $latex N$ đến nó bằng $latex 5$.

Bài 3. Cho $latex A(1;2),B(5;-1)$. Viết phương trình đường thẳng qua $latex (3;5)$ và cách đều $latex A,B$.

Bài 4. Cho $latex A(1;1),B(4;-3)$. Tìm $latex C$ thuộc $latex d:x-2y-1=0$ sao cho $latex d(C,AB)=6$.

Bài 5. Cho $latex d_1:x+y+3=0,d_2:x-y-4=0;d_3:x-2y=0$. Tìm $latex Min d_3$ để $latex d(M,d_1)=2d(M,d_2)$.

View original post 76 more words