Calculator version 2 using AI Python

  Рет қаралды 83

T.J Moir

T.J Moir

Ай бұрын

Using a few AI large language models to produce a Scientific calculator very quickly. Shows the power of code copilot. This is a large button calculator for those with poor eyesight. Code listing is in Python and I put it in the first comment.

Пікірлер: 4
@johnsim3722
@johnsim3722 Ай бұрын
I see now how Geordi La Forge was able to program the Enterprise so easily! The computer doing its own programming.
@TJMoir
@TJMoir Ай бұрын
Sci Fi and fact are getting closer by the day. A robot that needs to change software for a manipulator might well create its own code! Humans would have to prevent it from updating itself. at present of course it has no consciousness but it is thought in a few years......
@johnsim3722
@johnsim3722 Ай бұрын
@@TJMoir Where we're going to get to first is where an AI decides it needs a type of function and writes it. What it does from there, and how quickly it advances off that point, really is the stuff of Sci Fi. Terminator etc. where the AI takes over, but it's not the first. Look at Colossus: The Forbin Project, or even War Games.
@TJMoir
@TJMoir Ай бұрын
Here's the code. import tkinter as tk import math class ScientificCalculator: def __init__(self, master): self.master = master master.title("Scientific Calculator") master.configure(bg='silver') self.display = tk.Entry(master, font=("Arial", 24), width=30, justify='right', bd=10, relief="sunken", bg='white') self.display.grid(row=0, column=0, columnspan=5, padx=10, pady=10) self.buttons = {} self.create_buttons() self.radians = True def create_buttons(self): buttons = [ 'C', '(', ')', '/', 'sqrt', '7', '8', '9', '*', 'x^y', '4', '5', '6', '-', 'sin', '1', '2', '3', '+', 'cos', '0', '.', '=', 'tan', '1/x', 'arcsin', 'arccos', 'arctan', 'Rad', 'exp(x)', 'π', '+/-', '%', 'ln', 'log10', 'x^2' ] row = 1 col = 0 for i, button in enumerate(buttons): command = lambda x=button: self.click(x) self.buttons[button] = tk.Button(self.master, text=button, font=("Arial", 18), command=command, height=2, width=5, bd=5, relief="raised", bg='lightgray') self.buttons[button].grid(row=row, column=col, sticky='nsew', padx=5, pady=5) col += 1 if col > 4: col = 0 row += 1 def click(self, key): if key == '=': try: expression = self.display.get() if '%' in expression: nums = expression.split('%') result = float(nums[0]) * float(nums[1]) / 100 else: result = eval(expression) self.display.delete(0, tk.END) self.display.insert(tk.END, str(result)) except: self.display.delete(0, tk.END) self.display.insert(tk.END, "Error") elif key == 'C': self.display.delete(0, tk.END) elif key == '+/-': try: current_value = float(self.display.get()) new_value = -current_value self.display.delete(0, tk.END) self.display.insert(tk.END, str(new_value)) except: self.display.delete(0, tk.END) self.display.insert(tk.END, "Error") elif key == 'x^2': try: value = float(self.display.get()) result = value ** 2 self.display.delete(0, tk.END) self.display.insert(tk.END, str(result)) except: self.display.delete(0, tk.END) self.display.insert(tk.END, "Error") elif key in ['sin', 'cos', 'tan']: try: value = float(self.display.get()) if not self.radians: value = math.radians(value) result = getattr(math, key)(value) self.display.delete(0, tk.END) self.display.insert(tk.END, str(result)) except: self.display.delete(0, tk.END) self.display.insert(tk.END, "Error") elif key in ['arcsin', 'arccos', 'arctan']: try: value = float(self.display.get()) if key in ['arcsin', 'arccos'] and (value < -1 or value > 1): raise ValueError("Input out of range for arcsin/arccos") result = getattr(math, 'a' + key[3:])(value) if not self.radians: result = math.degrees(result) self.display.delete(0, tk.END) self.display.insert(tk.END, str(result)) except Exception as e: self.display.delete(0, tk.END) self.display.insert(tk.END, f"Error: {str(e)}") elif key == 'sqrt': try: result = math.sqrt(float(self.display.get())) self.display.delete(0, tk.END) self.display.insert(tk.END, str(result)) except: self.display.delete(0, tk.END) self.display.insert(tk.END, "Error") elif key == 'x^y': self.display.insert(tk.END, '**') elif key == 'exp': self.display.insert(tk.END, 'math.exp(') elif key == '1/x': try: result = 1 / float(self.display.get()) self.display.delete(0, tk.END) self.display.insert(tk.END, str(result)) except: self.display.delete(0, tk.END) self.display.insert(tk.END, "Error") elif key == 'Rad': self.radians = not self.radians self.buttons['Rad'].config(text="Rad" if self.radians else "Deg") elif key == 'exp(x)': try: value = float(self.display.get()) result = math.exp(value) self.display.delete(0, tk.END) self.display.insert(tk.END, str(result)) except: self.display.delete(0, tk.END) self.display.insert(tk.END, "Error") elif key == 'π': self.display.insert(tk.END, str(math.pi)) elif key == 'ln': try: value = float(self.display.get()) result = math.log(value) self.display.delete(0, tk.END) self.display.insert(tk.END, str(result)) except: self.display.delete(0, tk.END) self.display.insert(tk.END, "Error") elif key == 'log10': try: value = float(self.display.get()) result = math.log10(value) self.display.delete(0, tk.END) self.display.insert(tk.END, str(result)) except: self.display.delete(0, tk.END) self.display.insert(tk.END, "Error") else: self.display.insert(tk.END, key) root = tk.Tk() for i in range(1, 7): root.grid_rowconfigure(i, weight=1) for i in range(5): root.grid_columnconfigure(i, weight=1) calculator = ScientificCalculator(root) root.mainloop()
Data Modeling for Power BI [Full Course] 📊
2:34:41
Pragmatic Works
Рет қаралды 3,2 МЛН
50 YouTubers Fight For $1,000,000
41:27
MrBeast
Рет қаралды 210 МЛН
A little girl was shy at her first ballet lesson #shorts
00:35
Fabiosa Animated
Рет қаралды 15 МЛН
Sigma girl and soap bubbles by Secret Vlog
00:37
Secret Vlog
Рет қаралды 14 МЛН
World’s Largest Jello Pool
01:00
Mark Rober
Рет қаралды 99 МЛН
Writing a Screen Scraper in Python helped by AI
14:21
T.J Moir
Рет қаралды 40
Control systems in mathematical algorithms
53:35
T.J Moir
Рет қаралды 135
Adam Savage's Latest Flea Market Haul!
11:05
Adam Savage’s Tested
Рет қаралды 105 М.
AI Scottish Music
39:25
T.J Moir
Рет қаралды 26
Creating an executable in Python
11:45
T.J Moir
Рет қаралды 60
Unitree Robotics robot
1:14
T.J Moir
Рет қаралды 136
НОВЫЕ ФЕЙК iPHONE 🤯 #iphone
0:37
ALSER kz
Рет қаралды 353 М.
Как удвоить напряжение? #электроника #умножитель
1:00
Hi Dev! – Электроника
Рет қаралды 1,1 МЛН
Better Than Smart Phones☠️🤯 | #trollface
0:11
Not Sanu Moments
Рет қаралды 15 МЛН