Python ile Basit Market ve Kumbara yazılım örnekleri.

İkisinin de çalışma mantığı aynı biri sadece paranızı biriktirmek amacı ile diğeri ise bir fırındaki hesabı yapmak için kullanılıyor.
Kumbara örneği:
Python:
from tkinter import *


with open("birikmis.txt") as dsya:
    bir=int(dsya.read())

def cikis():
    with open("birikmis.txt","w") as dsy:
        dsy.write(str(sayi["text"]))
        root.destroy()
def sifirla():
    sayi["text"]=0
   
def a5():
    sayi["text"]=sayi["text"]+5
   
       
def b10():
    sayi["text"]=sayi["text"]+10

   
def c20():
    sayi["text"]=sayi["text"]+20


   
def d50():
    sayi["text"]=sayi["text"]+50

   
def e100():
    sayi["text"]=sayi["text"]+100


   
def f200():
    sayi["text"]=sayi["text"]+200


root=Tk()
root.protocol("WM_DELETE_WINDOW",cikis)


sayi=Label(root,text=bir)
sayi.pack()

buton1=Button(root,text="Kumbaraya 5TL AT",width=30, height=2 ,command=a5)
buton1.pack()

buton2=Button(root,text="Kumbaraya 10TL AT",width=30, height=2 ,command=b10)
buton2.pack()

buton3=Button(root,text="Kumbaraya 20TL AT",width=30, height=2 ,command=c20)
buton3.pack()

buton4=Button(root,text="Kumbaraya 50TL AT",width=30, height=2 ,command=d50)
buton4.pack()

buton5=Button(root,text="Kumbaraya 100TL AT",width=30, height=2 ,command=e100)
buton5.pack()

buton6=Button(root,text="Kumbaraya 200TL AT",width=30, height=2 ,command=f200)
buton6.pack()

buton7=Button(root,text="Kumbarada ki parayı sil.",width=30, height=2 ,command=sifirla)
buton7.pack()

mainloop()

Örnek Fotoğraf:



Dikkat bu örnekte birikmis.txt adında bir .txt belgesi olmalı ve içinde sıfır yazmalı.

Python:
from tkinter import *


with open("hesap.txt") as dsya:
    hes=int(dsya.read())

def cikis():
    with open("hesap.txt","w") as dsy:
        dsy.write(str(sayi["text"]))
        root.destroy()
def sifirla():
    sayi["text"]=0
   
def ekmek():
    sayi["text"]=sayi["text"]+4
   
def tambug():
    sayi["text"]=sayi["text"]+6

def sim():
    sayi["text"]=sayi["text"]+2
   
def pog():
    sayi["text"]=sayi["text"]+3

def apide():
    sayi["text"]=sayi["text"]+9
   
def bacma():
    sayi["text"]=sayi["text"]+3

def ctra():
    sayi["text"]=sayi["text"]+9


def som():
    sayi["text"]=sayi["text"]+5

def bak():
    sayi["text"]=sayi["text"]+10

def hal():
    sayi["text"]=sayi["text"]+2.5

root=Tk()
root.protocol("WM_DELETE_WINDOW",cikis)


sayi=Label(root,text=hes)
sayi.pack()

buton=Button(root,text="Normal ekmek",width=30, height=2  , command=ekmek)
buton.pack()


buton9=Button(root,text="Somon Ekmek",width=30, height=2  , command=som)
buton9.pack()

buton2=Button(root,text="Tam buğday ekmeği ",width=30, height=2 ,command=tambug)
buton2.pack()


buton7=Button(root,text="Trabzon Ekmeği",width=30, height=2 ,command=ctra)
buton7.pack()

buton5=Button(root,text=" Pide",width=30, height=2 ,command=apide)
buton5.pack()

buton3=Button(root,text=" Simit ",width=30, height=2 ,command=sim)
buton3.pack()

buton4=Button(root,text="Poğaça ",width=30, height=2,command=pog)
buton4.pack()

buton6=Button(root,text="Açma",width=30, height=2 ,command=bacma)
buton6.pack()


buton8=Button(root,text="Hesabı Sil.",width=30, height=2 ,command=sifirla)
buton8.pack()

mainloop()

Örnek Fotoğraf:



Dikkat bu örnekte hesap.txt adında bir .txt belgesi olmalı ve içinde sıfır yazmalı.
 
Son düzenleyen: Moderatör:
Method parametreleri 1945'te icat edildi. 1944'teki kodlar ⬆.

Şaka bir yana keşke az da olsa parametre kullansaydınız.
tüm parametreleri tek bir parametrede bile toplayabilirdi. (içindeki kodları kast ediyorum)
 
Merhaba,

Elinize sağlık, güzel olmuş. İlk örnek için bir kaç önerim olacak.

1. Eğer kullanıcıda 'birikmis.txt' adında bir dosya yoksa script kendi oluşturabilir mi?
2. Kumbarada ne kadar para olduğunu anlık görebilir miyiz?
3. Dosyaları açarken parametre kullanmayı deneyiniz. Çünkü öntanımlı karakter kodlaması linux/unix için utf-8 iken, windows için cp1252. Bu sebeple dosyalarınızı açarken şu şekilde açarsanız daha iyi olacaktır.
Python:
with open('kumbara.txt', mode='r', encoding='utf-8') as kmbr:
4. Her para birimi için ayrı ayrı def yapmak yerine bunları daha kısa bir şekilde tek bir fonksiyon içinde yazabilir misiniz?

İyi kodlamalar.
 
Vaktim olunca bakacağım sağ olun hocam.

2. Kumbarada ne kadar para olduğunu anlık görebilir miyiz?
Üst kısımda zaten sayı yazıyor .txt belgesinde ne kadar veri varsa o kadar yazıyor yani bir gün 5 TL attım başka hiçbir şeyi ellemedim bir başka gün o 5 TL gözükür.

1. Eğer kullanıcıda 'birikmis.txt' adında bir dosya yoksa script kendi oluşturabilir mi?
Oluşturabilir bir iki değişiklik ile ben çok sıkıntı çıkarmaması için elle oluşturma yaptım.
 
Bu siteyi kullanmak için çerezler gereklidir. Siteyi kullanmaya devam etmek için çerezleri kabul etmelisiniz. Daha Fazlasını Öğren.…