12 Aralık 2020 Cumartesi

Dosya İşlemleri (Ekleme-Arama-Silme)

import os
class patiensInfo:
def __init__(self, name=None, surname=None, patientId=None):
self.name = name,
self.surname = surname,
self.patientId = patientId,
self.filename='patient.txt'

def __str__(self):
return '[Name: {0} | Surname: {1} | PatientId: {2}]'.\
format(self.name, self.surname, self.patientId)
def __repr__(self):
return '[Name: {0} | Surname: {1} | PatientId: {2}]'.\
format(self.name, self.surname, self.patientId)

def patient_add(self):
self.name=input("Patient name: ")
self.surname = input("Patient surname: ")
self.patientId = input("Patient patientId: ")
try:
if os.path.exists(self.filename) and os.path.getsize(self.filename)>0:
myPatientDb= open(self.filename, 'a')
myPatientDb.write(self.name+" "+self.surname+" "+self.patientId+"\n")
else:
myPatientDb = open(self.filename, 'w')
myPatientDb.write(self.name+" "+self.surname+" "+self.patientId+"\n")
except IOError:
print("Bir hata oluştu!")
finally:
myPatientDb.close()

def displayPatients(self):
if os.path.exists(self.filename) and os.path.getsize(self.filename) > 0:
myPatientDb = open(self.filename, 'r')
for records in myPatientDb:
print(records, end="")
myPatientDb.close()

def searchPatients(self):
if os.path.exists(self.filename) and os.path.getsize(self.filename) > 0:
myPatientDb = open(self.filename, 'r')
try:
patientsSearch = input("Enter the patientId: ")
counter = 0
for patient in myPatientDb.readlines():
if patientsSearch == patient.split()[2]:
print(patient)
counter +=1
if counter == 0:
print("No record found whose name is:", patientsSearch)
except:
print("Error occured!")
else:
print("No record in patient.txt")

def deletePatient(self):
if os.path.exists(self.filename) and os.path.getsize(self.filename)>0:
myPatientDb = open(self.filename, 'r')
try:
patientsSearch = input("Enter the patientId: ")
counter = 0
liste = myPatientDb.readlines()
for patient in liste:
if patientsSearch == patient.split()[2]:
k = liste.index(patient)
del liste[k]
myPatientDb.close()

myPatientDb = open(self.filename, 'w')
myPatientDb.writelines(liste)
myPatientDb.close()
counter +=1
if counter == 0:
print("No record found whose name is:", patientsSearch)
except:
print("Error occured!")
else:
print("No record in patient.txt")


if __name__ == '__main__':
ourPatiens = patiensInfo()
print("Enter 1.To add 2.For search 3.Display 4.Delete 5.Exit")
while True:
choice = input("Enter your choice: ").lower()
if choice == "1":
ourPatiens.patient_add()
elif choice == "2":
ourPatiens.searchPatients()
elif choice == "3":
ourPatiens.displayPatients()
elif choice == "4":
ourPatiens.deletePatient()
elif choice == 'q':
exit()
else:
print("Invalid option. Try again!")

27 Ekim 2020 Salı

Yıldız Ücgen Cizimi

 # def yildiz(level):

#     for i in range(0,level):
# print(" " * (level-i), end="")
# print("*" * (2*i-1))
#
# yildiz(7)

class yildiz(object):
def __init__(self):
self.deger = 0

def show(self, sayi):
self.deger = sayi
for i in range(0, self.deger+1):
print(" " * (self.deger-i), end="")
print("*" * (2*i-1))

if __name__ == '__main__':
userInput = int(input("Deger: "))
result = yildiz()
result.show(userInput)

25 Ekim 2020 Pazar

Asansör Kontrol Paneli

from time import sleep

print(" Wellcome ".center(60,"*"))
print("Please enter the number floor.")

class elevatorControlPanel:
def __init__(self):
self.sayac = 0

def whichFloor(self):
self.floorNumber = input("\nEnter the number floor: ")
if self.floorNumber == "":
quit()
else:
return int(self.floorNumber)

def get_number(self, number):
if self.numberFloor == 0:
if self.sayac < self.numberFloor:
print("Elevator is going up {}.Floor".format(self.numberFloor))
sleep(self.sayac / 2)
self.sayac = self.numberFloor
return print("{}.Floor".format(self.numberFloor))
else:
print("Elevator is going down {}.Floor".format(self.numberFloor))
sleep(self.sayac / 2)
self.sayac = self.numberFloor
return print("{}.Floor".format(self.numberFloor))

elif self.sayac < self.numberFloor:
self.sayac = self.numberFloor
print("Elevator is going up {}.Floor".format(self.numberFloor))
sleep(self.sayac/2)
return print("{}.Floor".format(self.numberFloor))

# print("{}.floor".format(self.numberFloor))
# return quit() #İf you want end of elevator all the floor

elif self.sayac > self.numberFloor:
self.sayac = self.numberFloor
print("Elevator is going down {}.Floor".format(self.numberFloor))
sleep(self.sayac/2)
return print("{}.Floor".format(self.numberFloor))

# print("{}.floor".format(self.numberFloor))
# return quit() #İf you want end of elevator all the floor
else:
print("Enter number the floor.")
quit()

def Loop(self):
while True:
self.numberFloor = self.whichFloor()
self.floor = self.get_number(self.numberFloor)

# def showScreen(self):
# message = "\nYou are goin to {}.floor"
# print(message.format(self.numberFloor))

def calistir(self):
self.loop = self.Loop()

if __name__ == '__main__':
floor = elevatorControlPanel()
floor.calistir()

23 Ekim 2020 Cuma

Quiz Osmanli Padişahları

 import random

osmanli = ["Osman Gazi", "Orhan Gazi", "I.Murat", "I.Bayezid", "I.Mehmed",
           "II.Murat", "II.Mehmed", "II.Bayezid","I.Selim", "I.Süleyman",
           "II.Selim", "III.Murad", "III.Mehmed", "I.Ahmed", "I.Mustafa",
           "II.Osman", "IV.Murad","İbrahim","IV.Mehmed", "II.Süleyman",
           "II.Ahmed", "II.Mustafa", "III.Ahmed", "I.Mahmud","III.Osman",
           "III.Mustafa","I.Abdülhamid","III.Selim", "IV.Mustafa",
           "II.Mahmud","Abdülmecid", "Abdülaziz", "V.Murad","II.Abdülhamid",
           "V.Mehmed", "VI.Mehmed"]
print(len(osmanli), "Osmanlı padişahı vardır.")
print("Bu padişahlardan 10 tanesi için soru sorulacaktır.\n
    Yanlış cevap verdiğinizde yarışma sonlanacaktır.\n
      Her doğru cevap 10 puandır. Hazırsanız başlayalım.")
puan = 0
soru = []
siklar = ["a", "b", "c", "d"]
while True:
for i in range(1, 11):
soruTipi = random.randrange(1, 3)
if soruTipi == 1:
soru = random.sample(osmanli, 1)
x =[i for i in range(osmanli.index(*soru), osmanli.index(*soru) + 4)]
random.shuffle(x)
# print(osmanli.index(*soru) + 1) #Kopya
print("{0}. Soru: {1} kaçıncı padişahtır".format(i, *soru))
for k, j in zip(siklar, x):
print("{}-) {} ".format(k, j), end="")
print()
cevap = input("")
if cevap == "":
print("Soruları boş geçilemez lütfen cevap verin")
print("{0}. Soru: {1} kaçıncı padişahtır".format(i, *soru))
for k, j in zip(siklar, x):
print("{}-) {} ".format(k, j), end="")
print()
cevap = input("")
elif str(osmanli.index(*soru) + 1) == cevap:
puan += 10
else:
break

elif soruTipi == 2:
soru = random.sample(osmanli, 4)
random.shuffle(soru)
# print(soru[0]) # Kopya
print("{0}.Soru: {1}.Osmanlı padişahı aşağıdakilerden hangisidir."
                   .format(i, (osmanli.index(soru[0]) + 1)))
for l, j in zip(siklar, soru):
print("{}-){} ".format(l, j), end="")
print()
cevap = input("")
if cevap == "":
print("Soruları boş geçilemez lütfen cevap verin")
print("{0}.Soru: {1}.Osmanlı padişahı aşağıdakilerden hangisidir."
                       .format(i, (osmanli.index(soru[0]) + 1)))
for l, j in zip(siklar, soru):
print("{}-){} ".format(l, j), end="")
print()
cevap = input("")
elif soru[0] == cevap:
puan += 10
else:
break

print("Puanınız: ", puan)
break

20 Ekim 2020 Salı

Hmtl

<!DOCTYPE html>
<html lang="en">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Bayram</title>
</head>
<body onload="deger()">
    <div class="container">
        <form id="frm" method="POST" action="#">
            <label>Username</label>
            <input type="text" id="name" name="name" />
            <label>Lastname</label>
            <input type="text" id="lastName" name="lastName" /
            <label>Email box</label>
            <input type="email" id="email" name="email" />
            <label id="wrt">Write box</label>
            <textarea type="text" id="textArea" name="Text">Write...</textarea>
            <input type="submit" name="submit" id="btn" />
        </form>
    </div>
</body>
</html>
/* Css ayarları */
* {
    box-sizing: border-box;
}
body {
    background-image: url(canyon.jpg);
    background-repeat: no-repeat;
    background-size: cover;
    font-family: "Times New Roman", Times, serif;
}
.container {
    position: absolute;
    top: 25%;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    text-align: center;
    justify-content: center;
}
#frm {
    border: 1px solid gray;
    box-shadow: 0 15px 15px 0 rgba(0, 0, 0, 0.6);
    background-color: #cc3000;
    width: 400px;
    height: 380px;
    padding-top: 8px;
}
label {
    color: white;
    font-size: 20px;
    display: block;
    margin-left: -290px;
    padding: 5px;
}
input[type="text"] {
    height: 30px;
    width: 370px;
    font-size: 15px;
}
input[type="text"]:focus {
    background-color: #66ccff;
    font-weight: bold;
    font-size: 25px;
}
input[type="email"] {
    height: 30px;
    width: 370px;
    font-size: 15px;
}
input[type="email"]:focus {
    background-color: #66ccff;
    font-weight: bold;
    font-size: 25px
}
#textArea {
    height: 90px;
    width: 370px;
}
#textArea:focus {
    font-weight: bold;
    font-size: 15px;
}
#btn {
    background-color: #999999;
    box-shadow: 0 15px 15px 0 rgba(0, 0, 0, 0.6);
    font-size: 20px;
    width: 150px;
    height: 30px;
    border: none;
    margin: 5px;
    box-shadow: 0 15px 15px 0 rgba(0, 0, 0, 0.3);
}
#btn:hover {
    background-color: white;
    font-weight: bold;
}

Ekranda Kayan Yazı

 from time import sleep


userInput = input("Herhangi bir karakter giriniz: ")

class KayanYazi(object):
print(" Kayan Yazi ".center(50, "*"))
def __init__(self, name):
self.name = name

def kayan_yazi(self):
for i in range(0,20):
print(self.name.rjust(len(self.name)+1," "), end="")
sleep(0.5)
print("".ljust(len(self.name),"\b") ,end="")
for i in range(0,20):
print(self.name.ljust(len(self.name), " "), end="")
sleep(0.5)
print("".rjust(len(self.name)+1,"\b") ,end="")

KayanYazi(userInput).kayan_yazi()

1 Ekim 2020 Perşembe


LinkedInwww.linkedin.com/in/bayram-ekin-b57082b9

Mail bayram.ekinn@gmail.com

Mekatronik Mühendisliği,  Gaziosmanpaşa Üniversitesi,  Tokat,  Türkiye



Python Pyqt5 ile Hesap Makinası

from PyQt5.QtWidgets import * from PyQt5.QtGui import * from mainUI import * from PyQt5.QtCore import * import sys # ----------------------U...