Learn Python in 30 Seconds | Project-Based Full Course | Make A Calculator

preview_player
Показать описание

#Shorts
Рекомендации по теме
Комментарии
Автор

a = int(input("first number:")) b = int(input("second number"))

print(a+b)

Ez one ⬆

a = int(input("first number:"))
b = int(input("second number:"))

count = a + b

print(count)

The medium one ⬆

def count():
a = int(input("first number: "))
b = int(input("second number: "))
counting = a + b
print(counting)
return counting

Logic ⬆


import tkinter as tk

def button_click(number):
current = entry.get()
entry.delete(0, tk.END)
entry.insert(tk.END, current + str(number))

def button_clear():
entry.delete(0, tk.END)

def button_equal():
expression = entry.get()
try:
result = eval(expression)
entry.delete(0, tk.END)
entry.insert(tk.END, result)
except:
entry.delete(0, tk.END)
entry.insert(tk.END, "Error")

# A tkinter ablak létrehozása
window = tk.Tk()
window.title("Calculator")

# Beviteli mező (Entry) létrehozása
entry = tk.Entry(window, width=30)
entry.grid(row=0, column=0, columnspan=4, padx=10, pady=10)

# Számok gombjainak létrehozása
button_1 = tk.Button(window, text="1", padx=20, pady=10, command=lambda: button_click(1))
button_2 = tk.Button(window, text="2", padx=20, pady=10, command=lambda: button_click(2))
button_3 = tk.Button(window, text="3", padx=20, pady=10, command=lambda: button_click(3))
button_4 = tk.Button(window, text="4", padx=20, pady=10, command=lambda: button_click(4))
button_5 = tk.Button(window, text="5", padx=20, pady=10, command=lambda: button_click(5))
button_6 = tk.Button(window, text="6", padx=20, pady=10, command=lambda: button_click(6))
button_7 = tk.Button(window, text="7", padx=20, pady=10, command=lambda: button_click(7))
button_8 = tk.Button(window, text="8", padx=20, pady=10, command=lambda: button_click(8))
button_9 = tk.Button(window, text="9", padx=20, pady=10, command=lambda: button_click(9))
button_0 = tk.Button(window, text="0", padx=20, pady=10, command=lambda: button_click(0))

button_1.grid(row=1, column=0)
button_2.grid(row=1, column=1)
button_3.grid(row=1, column=2)
button_4.grid(row=2, column=0)
button_5.grid(row=2, column=1)
button_6.grid(row=2, column=2)
button_7.grid(row=3, column=0)
button_8.grid(row=3, column=1)
button_9.grid(row=3, column=2)
button_0.grid(row=4, column=0)

# Műveleti jelek gombjainak létrehozása
button_plus = tk.Button(window, text="+", padx=19, pady=10, command=lambda: button_click("+"))
button_minus = tk.Button(window, text="-", padx=20, pady=10, command=lambda: button_click("-"))
button_multiply = tk.Button(window, text="*", padx=20, pady=10, command=lambda: button_click("*"))
button_divide = tk.Button(window, text="/", padx=20, pady=10, command=lambda: button_click("/"))

button_plus.grid(row=1, column=3)
button_minus.grid(row=2, column=3)
button_multiply.grid(row=3, column=3)
button_divide.grid(row=4, column=3)

# Egyenlőségjel gombja
button_equal = tk.Button(window, text="=", padx=46, pady=10, command=button_equal)
button_equal.grid(row=4, column=1, columnspan=2)

# Törlés gombja
button_clear = tk.Button(window, text="Clear", padx=36, pady=10, command=button_clear)
button_clear.grid(row=5, column=0, columnspan=4)

# Ablak megjelenítése
window.mainloop()


Master ⬆

ikslay
Автор

*Only a month old person will realize they don’t know what A is or B*

MineKnightMC
Автор

u can also try program(any number and use * to multiply and + to add )

Kachxitori
Автор

or maybe print(eval(f'{input()}'))
you have to make the equation like:
2+2

idonyknow
Автор

Danm, I knows how to code now! Thankz!

nykel
Автор

Python actually counted the length of a and b input value😂

RKPOST
Автор

is that YK from CS Dojo ?? i love hiiimm

Salmaaaaaaaaaaaaaaaaaa
Автор

On the console side, are you pressing enter to get it to say the second number because when I press enter it just stops running

oohneFr
Автор

a = int(input("first number: ")
b = int(input("second number: ")

print(a+b)
this is easy

Rizwan__
Автор

Half of these people in the comment section are kids and the other is bunch of programmers

Laraxoxx
Автор

Why learn python right now if AI will replace python Developers faster than any other language?

xander