Hesap Makinem - python

basuringoismail

Bronz Üye
Katılım
27 Ocak 2026
Mesajlar
32
Beğeniler
34
Nasıl olmuş yeni yaptım
Python:
while True:
    print("\n--- HESAP MAKİNESİ ---")
    print("1 - Toplama")
    print("2 - Çıkarma")
    print("3 - Çarpma")
    print("4 - Bölme")
    print("q - Çıkış")

    secim = input("İşlem seçin: ")

    if secim == "q":
        print("Programdan çıkılıyor...")
        break

    if secim not in ["1", "2", "3", "4"]:
        print("Geçersiz seçim!")
        continue

    try:
        sayi1 = float(input("1. sayıyı girin: "))
        sayi2 = float(input("2. sayıyı girin: "))
    except ValueError:
        print("Hatalı giriş! Lütfen sayı girin.")
        continue

    if secim == "1":
        sonuc = sayi1 + sayi2
        print("Sonuç:", sonuc)

    elif secim == "2":
        sonuc = sayi1 - sayi2
        print("Sonuç:", sonuc)

    elif secim == "3":
        sonuc = sayi1 * sayi2
        print("Sonuç:", sonuc)

    elif secim == "4":
        if sayi2 == 0:
            print("Hata! Bir sayı 0'a bölünemez.")
        else:
            sonuc = sayi1 / sayi2
            print("Sonuç:", sonuc)
 
elif secim == "4" de hata var 0 ile bolmeye calısınca mavi ekran vermesı lazımdı
 
çok uğraştınmı yapmak için
 
Bu kullanıcıyla herhangi bir iş veya ticaret yapmak istiyorsanız, forumdan uzaklaştırıldığını sakın unutmayın.
Python:
import math
from decimal import Decimal, getcontext
import sys

getcontext().prec = 28
getcontext().traps[Decimal.DivisionByZero] = False

class Renk:
    YESIL = '\033[92m'
    SARI  = '\033[93m'
    KIRMIZI = '\033[91m'
    MAVI   = '\033[94m'
    NORMAL = '\033[0m'

def temizle_ekrani():
    print("\033c", end="")

def hata_yaz(mesaj):
    print(f"{Renk.KIRMIZI}HATA: {mesaj}{Renk.NORMAL}")

def basarili_sonuc(yazi):
    print(f"{Renk.YESIL}→ {yazi}{Renk.NORMAL}")

def hesapla_ifade(ifade):
    try:
        temiz_ifade = "".join(c for c in ifade if c.isdigit() or c in "+-*/().,^%√!eπ ")
       
        temiz_ifade = temiz_ifade.replace('^', '**')
        temiz_ifade = temiz_ifade.replace('√', 'math.sqrt')
        temiz_ifade = temiz_ifade.replace('π', 'math.pi')
        temiz_ifade = temiz_ifade.replace('e', 'math.e')
       
        if '!' in temiz_ifade:
            temiz_ifade = factorial_hack(temiz_ifade)
       
        sonuc = eval(temiz_ifade, {"__builtins__": {}}, {
            "math": math,
            "Decimal": Decimal,
            "sin": math.sin,
            "cos": math.cos,
            "tan": math.tan,
            "asin": math.asin,
            "acos": math.acos,
            "atan": math.atan,
            "l0g": math.l0g,
            "log10": math.log10,
            "exp": math.exp,
            "sqrt": math.sqrt,
            "pow": math.pow,
            "fabs": math.fabs,
            "degrees": math.degrees,
            "radians": math.radians,
        })
       
        if isinstance(sonuc, (int, float)):
            if abs(sonuc) > 1e12 or (abs(sonuc) < 1e-8 and sonuc != 0):
                return f"{sonuc:.6e}"
        return sonuc
   
    except ZeroDivisionError:
        return "sıfıra bölme hatası"
    except ValueError as ve:
        return f"matematiksel hata → {ve}"
    except Exception as e:
        return f"hata → {str(e)}"

def factorial_hack(s):
    parts = []
    i = 0
    while i < len(s):
        if s[i] == '!':
            num_str = ""
            j = i-1
            while j >= 0 and (s[j].isdigit() or s[j] in '.'):
                num_str = s[j] + num_str
                j -= 1
            if num_str:
                num = int(float(num_str))
                if num > 170:
                    return "170! çok büyük"
                fact = 1
                for k in range(1, num+1):
                    fact *= k
                parts.append(str(fact))
            else:
                parts.append('!')
            i += 1
        else:
            parts.append(s[i])
            i += 1
    return "".join(parts)

def main():
    print(f"{Renk.MAVI}=== Hesap Makinesi ==={Renk.NORMAL}")
    print("q veya quit ile çık")
    print("-"*30)

    while True:
        try:
            giris = input(f"{Renk.SARI}> {Renk.NORMAL}").strip()
           
            if not giris:
                continue
               
            if giris.lower() in ('q', 'quit', 'çık', 'exit'):
                break
               
            if giris.lower() == 'temizle':
                temizle_ekrani()
                continue
               
            sonuc = hesapla_ifade(giris)
           
            if isinstance(sonuc, str) and ("hata" in sonuc.lower() or "bölme" in sonuc):
                hata_yaz(sonuc)
            else:
                basarili_sonuc(sonuc)
               
        except KeyboardInterrupt:
            sys.exit(0)
        except Exception as e:
            hata_yaz(str(e))

if __name__ == "__main__":
    main()

BENİMKİ DAHA İYİ BİRKERE

bu sefer yapay zekasız
 

Şuanda konuyu görüntüleyen kullanıcılar

Geri
Üst Alt