Friday, May 8, 2020


Membuat Kalkulator Sederhana Menggunakan Python

Kalkulator ialah alat yang digunakan untuk menghitung cepat. Kalkulator diprogram untuk dapat menyelesaikan masalah perhitungan dari tambah, kurang, bagi, kali, pangkat, hingga logaritma. Berikut adalah cara membuat kalkulator sederhana.
1.       Gunakan kode dibawah ini, copy dan simpan dalam format .py (python extension).

import sys
from math import sqrt
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *

num = 0.0
newNum = 0.0
sumIt = 0.0
sumAll = 0.0
operator = ""

opVar = False

class Calc(QMainWindow):

    def __init__(self):
        QMainWindow.__init__(self)
        self.initUI()

    def initUI(self):
        self.line = QLineEdit(self)
        self.line.move(5, 5)
        self.line.setReadOnly(True)
        self.line.setAlignment(Qt.AlignRight)
        font = self.line.font()
        font.setPointSize(40)
        self.line.setFont(font)
        self.line.resize(266, 70)

        zero = QPushButton("0", self)
        zero.move(5, 265)
        zero.resize(45, 40)

        one = QPushButton("1", self)
        one.move(5, 215)
        one.resize(45, 40)

        two = QPushButton("2", self)
        two.move(60, 215)
        two.resize(45, 40)

        three = QPushButton("3", self)
        three.move(115, 215)
        three.resize(45, 40)

        four = QPushButton("4", self)
        four.move(5, 165)
        four.resize(45, 40)

        five = QPushButton("5", self)
        five.move(60, 165)
        five.resize(45, 40)

        six = QPushButton("6", self)
        six.move(115, 165)
        six.resize(45, 40)

        seven = QPushButton("7", self)
        seven.move(5, 115)
        seven.resize(45, 40)

        eight = QPushButton("8", self)
        eight.move(60, 115)
        eight.resize(45, 40)

        nine = QPushButton("9", self)
        nine.move(115, 115)
        nine.resize(45, 40)

        switch = QPushButton("+/-", self)
        switch.move(60, 265)
        switch.resize(45, 40)
        switch.clicked.connect(self.Switch)

        point = QPushButton(".", self)
        point.move(115, 265)
        point.resize(45, 40)
        point.clicked.connect(self.Point)

        plus = QPushButton("+", self)
        plus.move(170, 265)
        plus.resize(45, 40)

        minus = QPushButton("-", self)
        minus.move(170, 215)
        minus.resize(45, 40)

        multiply = QPushButton("*", self)
        multiply.move(170, 165)
        multiply.resize(45, 40)

        divide = QPushButton("/", self)
        divide.move(170, 115)
        divide.resize(45, 40)

        equals = QPushButton("=", self)
        equals.move(225, 215)
        equals.resize(45, 90)
        equals.clicked.connect(self.Equal)

        squared = QPushButton("x²", self)
        squared.move(225, 165)
        squared.resize(45, 40)
        squared.clicked.connect(self.Squared)

        root = QPushButton("√", self)
        root.move(225, 115)
        root.resize(45, 40)
        root.clicked.connect(self.Root)

        ce = QPushButton("CE", self)
        ce.move(54, 75)
        ce.resize(112, 40)
        ce.clicked.connect(self.CE)

        c = QPushButton("C", self)
        c.move(164, 75)
        c.resize(112, 40)
        c.clicked.connect(self.C)


        nums = [zero, one, two, three, four, five, six, seven, eight, nine]

        operators = [ce, c, plus, minus, multiply, divide, equals]

        others = [switch, squared, root, point]

        for i in nums:
            i.setStyleSheet("color:blue;")
            i.clicked.connect(self.Num)

        for i in operators:
            i.setStyleSheet("color:red;")
        for i in operators[2:]:
            i.clicked.connect(self.operator)
        for i in others:
            i.setStyleSheet("color:red;")

        # Window Settings

        self.setGeometry(300, 300, 273, 320)
        self.setWindowTitle("Calculator")
        self.setFixedSize(273, 320)
        self.show()

    def Num(self):
        global num
        global newNum
        global opVar

        sender = self.sender()

        newNum = int(sender.text())
        setNum = str(newNum)

        if opVar == False:
            self.line.setText(self.line.text() + setNum)
        else:
            self.line.setText(setNum)
            opVar = False

    def operator(self):
        global sumIt
        global num
        global opVar
        global operator

        sumIt += 1

        if sumIt > 1:
            self.Equal()

        num = self.line.text()
        sender = self.sender()
        operator = sender.text()

        opVar = True

    def Equal(self):
        global sumIt
        global sumAll
        global num
        global newNum
        global operator
        global opVar

        sumIt = 0

        newNum = self.line.text()

        if operator == "+":
            sumAll = float(num) + float(newNum)
        elif operator == "-":
            sumAll = float(num) - float(newNum)
        elif operator == "*":
            sumAll = float(num) * float(newNum)
        elif operator == "/":
            sumAll = float(num) / float(newNum)

        self.line.setText(str(sumAll))
        opVar = True

    def Root(self):
        global num

        num = float(self.line.text())
        num = sqrt(num)
        self.line.setText(str(num))

    def Squared(self):
        global num

        num = float(self.line.text())
        num = num**2
        self.line.setText(str(num))

    def Point(self):

        if "." not in self.line.text():
            self.line.setText(self.line.text() + ".")

    def Switch(self):
        global num

        num = float(self.line.text())
        num = -num
        self.line.setText(str(num))

    def CE(self):
        self.line.backspace()

    def C(self):
        global num
        global newNum
        global sumAll
        global operator

        self.line.clear()

        num = 0.0
        newNum = 0.0
        sumAll = 0.0
        operator = ""

def main():
    app = QApplication(sys.argv)
    main = Calc()
    main.show()
    sys.exit(app.exec_())

if __name__ == "__main__":
    main()


Kamu bisa men-copy kode diatas lalu paste di program koding seperti Visual Studio Code. Lalu menyimpannya dalam format .py atau kamu juga bisa men-copy dan paste di notepad, lalu pilih save as. Kemudian pilih All Files, berikan nama pada dokumenmu lalu tambahkan .py dibelakangnya.

2.       Jangan lupa tempat kamu menyimpan kode tadi. Copy address file.py. Jika sudah lanjut ke step 3, jika belum, buka My Files lagi lalu cari tempat kamu menyimpan kode tadi. Jika sudah ketemu, klik kanan dan klik properties. Cari tulisan “Location” copy semua tulisan yang ada disana.

Misalnya:
C:\Users\MYPC\Desktop\HTML\calculator.py

3.       Buka aplikasi command promt lalu jalankan sebagai admininstrator. Bagi yang belum tahu command prompt, mungkin bertanya “Apasih command prompt?” atau “Gimana caranya buka aplikasi command prompt?” Yaa caranya mudah, kamu tinggal buka search yang ada di pojok kiri bawah atau bisa juga dengan menekan tombol Windows lalu ketik “cmd” di kotak pencarian (bagi windows 8 dan 10). Untuk windows 7 kamu dapat membuka My Files, kemudian tekan “Search” lalu ketik “cmd” di kotak pencarian. Selanjutnya tinggal klik kanan pada aplikasi “Command Prompt” lalu pilih “Run as Admininstrator”. Aplikasi akan terbuka sendiri nantinya.

4.       Selanjutnya tulis ini di Command Prompt:

python <paste kode tadi>

Nanti akan jadi seperti ini:

python C:\Users\Lenovo\Desktop\HTML\calculator.txt

Tekan Enter, aplikasi kalkulator mini akan terbuka dengan sendirinya di layar PC mu!

Thursday, April 30, 2020


Text Analysis: Immigration

Problem:
Unidentified people in America, who is illegally enter the country. To face this problem, Donald Trump is going to build up a wall border and drive out all the illegal immigrants out of the country.

Donald Trump:
He said that unidentified immigrants is bad. They killed a lot of kids in America, did what they wanted to in America which is not their country. That’s why according to Donald, making a strong border is a good decision to make. He will drive out all the illegal immigrants, and build a wall border to prevent illegal immigrants go into the country. Barrack Obama once drive out millions of people out of the country. Donald will do it again.

Hillary Clinton:
She disagreed Donald’s idea. Because it’s going to separate the children from their parent. The children were born in America, but their parent don’t. The parents had been working so hard for the country’s economy, it’s good for America. Rather than drive the out of the country, legalize them and encourage them to build up economy together is better. Also, drive out all the illegal immigrants is just too complicated. It’s not as easy as talking. Clinton said that Donald once exploit illegal immigrants to build up Trump Tower. Donald hire up a lot of illegal workers and pay them small wages. Clinton won’t make it happen again, she will make them out from their hiding and build up strong economy together. She won’t make anyone likes Donald to exploit the illegal immigrants again.

Wednesday, April 29, 2020


Listening Diary Second Semester 3.3

Name                                    :  Hanura Dustin Mahatma
Student Number                    :  19202241097

Website
Audio Name
Level/other information
https://www.youtube.com/watch?v=HFQAP2crH1A
How to Finish What You Start (Every Time)
Intermediate

Summary: What was the listening selection about?
The video encourage us to finish what we started. Anything, likes project, work, even dream. Because people will not remember someone who only dreaming. But people will remember someone who make their dream came true. Struggle what you started until it all finished than just abandon it. If you’re not going to struggle for it, don’t start it.

Vocabularies/language expressions you learnt
      1.   struggle

   

Activities: What did you do? What scores did you get?
I noted it in my head it’s true that finishing what we started rather than just abandon it is a good thing.

Self-Assessment
Questions
Yes
No
Maybe
The speed was OK.
X
The vocabulary was OK.
X
The pronunciation was OK.
X
This helped my listening skills.
X
I think my listening skills are improving.
X
I need to improve (please circle all that apply): listening to main ideas/listening to details/listening to numbers/listening to fast speech/listening to connected speech/listening for a long time/listening to other accents/my vocabulary/my pronunciation.
X




Thursday, March 19, 2020


Listening Diary Second Semester 3.2

Name                                    :  Hanura Dustin Mahatma
Student Number                    :  19202241097

Website
Audio Name
Level/other information
https://www.youtube.com/watch?v=S_1_ZSMxRfg
How to Make Club Sandwiches - Club Sandwich Recipe
Beginner

Summary: What was the listening selection about?
Untensils Needed:
      1.      Frying Pan
      2.      Stove
      3.      Spatula
      4.      Plate
      5.      Knife
      6.      Frilly Toothpicks

Ingredients:
      1.      Bacon
      2.      Smoked ham
      3.      Tomatoe
      4.      Toasted breads
      5.      Lettuce
      6.      Mayonaise
      7.      Turkey breast
      8.      French fries

Steps:
      1.      Cook up some bacons. Once it cooked, remove it from the pan then dry it.
      2.      Get a tomatoe then slice it into kind of thin-ish slices.
      3.      Take a toasted bread and cover it with mayonaise then put regular smoked ham above it. You can also add sliced turkey breast above it. You can also add sliced mild cheddar cheese on top of it.
      4.      Take the second toast, then cover it with mayonaise. Then put it upside down.
      5.      Cover the sandwich top with mayonaise again.
      6.      Put the cooked bacon and a nice piece of lettuce on top of it. Then get the 2 sliced tomatoes and put it right on top of it.
      7.      Get the third toasted bread and cover it with mayonaise again. Put it upside down.
      8.      Use frilly toothpicks to get the sandwich tighten. So you can slice the sandwich later easily.
      9.      Cut the sandwich into quarter.
      10.  Get a plate then put some french fries above, then serve the sandwich with french fries.
      11.  Enjoy!!

Vocabularies/language expressions you learnt
      1.   frilly

   

Activities: What did you do? What scores did you get?
I wrote the recipe. It’s pretty hard because of the ingredients.

Self-Assessment
Questions
Yes
No
Maybe
The speed was OK.
X
The vocabulary was OK.
X
The pronunciation was OK.
X
This helped my listening skills.
X
I think my listening skills are improving.
X
I need to improve (please circle all that apply): listening to main ideas/listening to details/listening to numbers/listening to fast speech/listening to connected speech/listening for a long time/listening to other accents/my vocabulary/my pronunciation.
X