Python Başlangıç - Hesap makinesi?

avatar LemonT
Forum Üyesi
10-12-2023, Saat: 11:30
173
#1
Yorumu Paylaş

Alıntı:# Toplama Fonksiyonu
def toplama(x, y):
    return x + y

# Çıkarma Fonksiyonu
def cikarma(x, y):
    return x - y

# Çarpma Fonksiyonu
def carpma(x, y):
    return x * y

# Bölme Fonksiyonu
def bolme(x, y):
    if y != 0:
        return x / y
    else:
        return "Geçersiz bölme! Payda sıfır olamaz."

# Kullanıcıdan Sayıları ve İşlemi Al
sayi1 = float(input("Birinci sayıyı girin: "))
sayi2 = float(input("İkinci sayıyı girin: "))
islem = input("Yapmak istediğiniz işlemi seçin (+, -, *, /): ")

# İşlemi Seç ve Sonucu Göster
if islem == "+":
    sonuc = toplama(sayi1, sayi2)
elif islem == "-":
    sonuc = cikarma(sayi1, sayi2)
elif islem == "*":
    sonuc = carpma(sayi1, sayi2)
elif islem == "/":
    sonuc = bolme(sayi1, sayi2)
else:
    sonuc = "Geçersiz işlem!"

# Sonucu Ekrana Yazdır
print(f"Sonuç: {sonuc}")
deneme
Forum Üyesi

Konuda Ara

0 Yorum


Konuyu Okuyanlar:
1 Ziyaretçi