Найти - Пользователи
Полная версия: Инженерный калькулятор, который считает в радианах и градах
Начало » Центр помощи » Инженерный калькулятор, который считает в радианах и градах
1
RuS_Skiy
Пытался дописать инженерный калькулятор что бы считал в градах и радианах, но он считает только в градах, а в радианы не переходит.
P.S. При нажатии на кнопки ‘RAD’ или ‘DEG’ меняется переменная и в зависимости от этой переменной считаются cos и sin

 from tkinter import *
from tkinter import messagebox
from tkinter import ttk
import math
import sys
root = Tk()
root.title("Calculator")
bttn_list = [
"7", "8", "9", "+", "*",
"4", "5", "6", "-", "/",
"1", "2", "3",  "=", "xⁿ",
"0", ".", "±",  "C",
"Exit", "π", "sin", "cos",
"(", ")","n!","√2", "RAD", "DEG" ]
r = 1
c = 0
for i in bttn_list:
    rel = ""
    cmd=lambda x=i: calc(x)
    ttk.Button(root, text=i, command = cmd, width = 10).grid(row=r, column = c)
    c += 1
    if c > 4:
        c = 0
        r += 1
calc_entry = Entry(root, width = 35)
calc_entry.grid(row=0, column=0, columnspan=5)
def calc(key):
    a = 'DEG'
    global memory
    if key == "=":
        str1 = "-+0123456789.*/)("
        if calc_entry.get()[0] not in str1:
            calc_entry.insert(END, "First symbol is not number!")
            messagebox.showerror("Error!", "You did not enter the number!")
        try:
            result = eval(calc_entry.get())
            calc_entry.insert(END, "=" + str(result))
        except:
            calc_entry.insert(END, "Error!")
            messagebox.showerror("Error!", "Check the correctness of data")
    elif key == "DEG":
        a = 'DEG'
        print(a)
    elif key == "RAD":
        a = 'RAD'
        print(a)
    elif key == "sin" and a == "RAD":
        calc_entry.insert(END, "=" + str(math.sin(math.degrees(int(calc_entry.get())))))
    elif key == "cos" and a == "RAD":
        calc_entry.insert(END, "=" + str(math.cos(math.degrees(int(calc_entry.get())))))
    elif key == "sin" and a == "DEG":
        calc_entry.insert(END, "=" + str(math.sin(math.radians(int(calc_entry.get())))))
    elif key == "cos" and a == "DEG":
        calc_entry.insert(END, "=" + str(math.cos(math.radians(int(calc_entry.get())))))
    elif key == "C":
        calc_entry.delete(0, END)
    elif key == "±":
        if "=" in calc_entry.get():
            calc_entry.delete(0, END)
        try:
            if calc_entry.get()[0] == "-":
                calc_entry.delete(0)
            else:
                calc_entry.insert(0, "-")
        except IndexError:
            pass
    elif key == "π":
        calc_entry.insert(END, math.pi)
    elif key == "Exit":
        root.after(1,root.destroy)
        sys.exit
    elif key == "xⁿ":
        calc_entry.insert(END, "**")
    elif key == "(":
        calc_entry.insert(END, "(")
    elif key == ")":
        calc_entry.insert(END, ")")
    elif key == "n!":
        calc_entry.insert(END, "=" + str(math.factorial(int(calc_entry.get()))))
    elif key == "√2":
        calc_entry.insert(END, "=" + str(math.sqrt(int(calc_entry.get()))))
    else:
        if "=" in calc_entry.get():
            calc_entry.delete(0, END)
        calc_entry.insert(END, key)
root.mainloop()


Прошу помогите…
tetrisgameaz
I have read your article; it is very informative and helpful for me. I admire the valuable information you offer in your articles. Thanks for posting it. Resurge Supplement
tetris

This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB