Notification texts go here Contact Us Click here

Scientific calculator using python

Please wait 0 seconds...
Scroll Down and click on Go to Link for destination
Congrats! Link is Generated
Creating a scientific calculator in Python involves building a user interface to handle
various mathematical operations and functions. You can use the `tkinter` library to create
the graphical user interface and implement the calculator's functionality.
Here'
s a basic example of how to create a scientific calculator using `tkinter`:
 
1. **Import Libraries:**
    Import the necessary libraries, including `tkinter` for GUI components and 
   `mathfor mathematical operations.
 
2. **Create GUI:**
   Build the calculator's user interface with buttons for digits, basic operators,
   and scientific functions.
 
3. **Implement Functionality:**
   Define functions for handling button clicks, performing calculations, 
   and displaying results.
 
4. **Run Application:**
   Run the `tkinter` event loop to start the calculator application.
 
```python Program : - 
 
```
 
  1. import tkinter as tk
  2. import math
  3.  
  4. class ScientificCalculatorApp:
  5.     def __init__(self, root):
  6.         self.root = root
  7.         self.root.title("Scientific Calculator")
  8.  
  9.         self.current_input = ""
  10.  
  11.         self.input_label = tk.Label(root, text="", font=("Helvetica", 24))
  12.         self.input_label.pack(pady=10)
  13.  
  14.         self.buttons = [
  15.             "7", "8", "9", "/",
  16.             "4", "5", "6", "*",
  17.             "1", "2", "3", "-",
  18.             "0", ".", "=", "+",
  19.             "sin", "cos", "tan",
  20.             "sqrt", "log", "exp",
  21.         ]
  22.  
  23.         self.create_buttons()
  24.  
  25.     def create_buttons(self):
  26.         for button_text in self.buttons:
  27.             button = tk.Button(self.root, text=button_text, font=("Helvetica", 18), command=lambda text=button_text: self.on_button_click(text))
  28.             button.pack(side=tk.LEFT, padx=10, pady=10)
  29.  
  30.     def on_button_click(self, text):
  31.         if text == "=":
  32.             try:
  33.                 result = eval(self.current_input)
  34.                 self.current_input = str(result)
  35.                 self.update_input_label()
  36.             except:
  37.                 self.current_input = "Error"
  38.                 self.update_input_label()
  39.         elif text == "sqrt":
  40.             self.current_input = str(math.sqrt(float(self.current_input)))
  41.             self.update_input_label()
  42.         elif text == "log":
  43.             self.current_input = str(math.log10(float(self.current_input)))
  44.             self.update_input_label()
  45.         elif text == "exp":
  46.             self.current_input = str(math.exp(float(self.current_input)))
  47.             self.update_input_label()
  48.         else:
  49.             self.current_input += text
  50.             self.update_input_label()
  51.  
  52.     def update_input_label(self):
  53.         self.input_label.config(text=self.current_input)
  54.  
  55. if __name__ == "__main__":
  56.     root = tk.Tk()
  57.     app = ScientificCalculatorApp(root)
  58.     root.mainloop()
  59.  
 
This example creates a basic scientific calculator with buttons for digits, basic operators,
and some common scientific functions like sine, cosine, tangent, square root, logarithm, and
exponential. The calculator evaluates expressions when the "=" button is pressed and 
displays the result.
 
Feel free to enhance this example by adding more scientific functions, handling corner cases,
 and improving the user interface.-09; ṃ/

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.