From 32dbf1a031c3bca6369ad84d932390b1882c2ede Mon Sep 17 00:00:00 2001 From: Mahmoud Mohammed <62524855+mmsaeed509@users.noreply.github.com> Date: Mon, 19 Dec 2022 19:47:24 +0200 Subject: [PATCH] updated python scripts added new python scripts for new python videos: User Input, Reading and Writing Files, Classes & Objects, and Building a Shoe Budget Tool. --- python/OOP/Employees.py | 18 ++++++++++ .../OOP/__pycache__/Employees.cpython-310.pyc | Bin 0 -> 673 bytes python/OOP/ouremployees.py | 12 +++++++ python/R-W_on_files/ReadingWriting.py | 33 ++++++++++++++++++ python/R-W_on_files/days.txt | 3 ++ python/R-W_on_files/months.txt | 12 +++++++ python/input.py | 29 +++++++++++++++ python/project/Shoes.py | 31 ++++++++++++++++ .../project/__pycache__/Shoes.cpython-310.pyc | Bin 0 -> 1149 bytes python/project/purchase.py | 13 +++++++ 10 files changed, 151 insertions(+) create mode 100644 python/OOP/Employees.py create mode 100644 python/OOP/__pycache__/Employees.cpython-310.pyc create mode 100644 python/OOP/ouremployees.py create mode 100644 python/R-W_on_files/ReadingWriting.py create mode 100644 python/R-W_on_files/days.txt create mode 100644 python/R-W_on_files/months.txt create mode 100644 python/input.py create mode 100644 python/project/Shoes.py create mode 100644 python/project/__pycache__/Shoes.cpython-310.pyc create mode 100644 python/project/purchase.py diff --git a/python/OOP/Employees.py b/python/OOP/Employees.py new file mode 100644 index 0000000..0aa2aed --- /dev/null +++ b/python/OOP/Employees.py @@ -0,0 +1,18 @@ +#!/bin/python3 + +class Employees: + + def __init__(self, name, department, role, salary, years_employed): + + self.name = name + self.department = department + self.role = role + self.salary = salary + self.years_employed = years_employed + + + def retirement(self): + if self.years_employed >= 20: + return True + else: + False diff --git a/python/OOP/__pycache__/Employees.cpython-310.pyc b/python/OOP/__pycache__/Employees.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..157a0c1ce0737bc20a467b69dd42a49a2c95fcf5 GIT binary patch literal 673 zcmY*WJx{|h5VajAO{2C$)scy<3xOS>N(dn_q?PED#foC17Lume>5wW+RQwKB{*qTF z{sI$siTc4s_w4hXeeYh1em@{!4{x982PNbigHv-Ln1Guhz&(*f(jE9ai-}~9WbCAH z{?8ah6L50|ph!$5iJ7F5?MUoMM{-!Xbm6XNyLb6ID=MW->OuA1aF5U2f}3-In$|>+ zngP<<0c14?bZQrnO9GG4XzW_PN^)fbsn&@ubG0fh*F~nRXOb+@l^s+n(MG7Ys{{tz zsO(8&GmWEaj^H97i7%pkSbi_VMUktp*eVkX&j4CMj($u3Sk2w@gV|CFV}*o9hi#|GMpUgB1n^7_vX2|A{sL literal 0 HcmV?d00001 diff --git a/python/OOP/ouremployees.py b/python/OOP/ouremployees.py new file mode 100644 index 0000000..ac63973 --- /dev/null +++ b/python/OOP/ouremployees.py @@ -0,0 +1,12 @@ +#!/bin/python3 + +from Employees import Employees + +employee_1 = Employees("Bob", "Sales", "Director of sales", 10000, 20) + +employee_2 = Employees("Linda", "Executive", "CIO", 15000, 10) + +print(employee_1.name) +print(employee_1.retirement()) + + diff --git a/python/R-W_on_files/ReadingWriting.py b/python/R-W_on_files/ReadingWriting.py new file mode 100644 index 0000000..720c186 --- /dev/null +++ b/python/R-W_on_files/ReadingWriting.py @@ -0,0 +1,33 @@ +#!/bin/python3 + +## --------- Reading --------- ## +months = open('months.txt') + +# print(months.read()) +# print(months.readline()) # read one line +# print(months.readlines()) # read all lines +print(months.read()) +# months.seek(0) # return to first line +# print(months.read()) + +# months.seek(0) # return to first line +# print("Print Using For loop ") +# for month in months: +# print(month) + +# months.seek(0) # return to first line +# print("Print Using For loop with strip method") +# for month in months: +# print(month.strip()) + +months.close() + +## --------- Writing --------- ## + +# arg 'w' for writing (overwrite), arg 'a' for append +days = open('days.txt', "a") + +days.write("Monday") +days.write("\nMonday") # '\n' fo new line + +days.close() diff --git a/python/R-W_on_files/days.txt b/python/R-W_on_files/days.txt new file mode 100644 index 0000000..deb66f1 --- /dev/null +++ b/python/R-W_on_files/days.txt @@ -0,0 +1,3 @@ +Monday +Monday +Monday \ No newline at end of file diff --git a/python/R-W_on_files/months.txt b/python/R-W_on_files/months.txt new file mode 100644 index 0000000..b46baa8 --- /dev/null +++ b/python/R-W_on_files/months.txt @@ -0,0 +1,12 @@ +Januray +February +March +April +May +June +July +August +September +October +November +December diff --git a/python/input.py b/python/input.py new file mode 100644 index 0000000..b9cf0ca --- /dev/null +++ b/python/input.py @@ -0,0 +1,29 @@ +#!/bin/python3 + +name = input("Enter your name: ") +print("Hello, Mr. " + name) + +# calculator # + +FIRST_NUMBER = float(input("Enter a number: ")) +OPERATOR = input("Enter an operator: ") +SECOND_NUMBER = float(input("Enter another number: ")) + +if OPERATOR == "+": + print(FIRST_NUMBER + SECOND_NUMBER) + +elif OPERATOR == "-": + print(FIRST_NUMBER - SECOND_NUMBER) + +elif OPERATOR == "*": + print(FIRST_NUMBER * SECOND_NUMBER) + +elif OPERATOR == "/": + print(FIRST_NUMBER / SECOND_NUMBER) + +elif OPERATOR == "**" or OPERATOR == "^": + print(FIRST_NUMBER ** SECOND_NUMBER) +else: + print("Unknown operator.") + + diff --git a/python/project/Shoes.py b/python/project/Shoes.py new file mode 100644 index 0000000..eec80b2 --- /dev/null +++ b/python/project/Shoes.py @@ -0,0 +1,31 @@ +#!/bin/python3 + +class Shoes: + + def __init__(self, name, price): + + self.name = name + self.price = float(price) + + def budget_check(self, budget): + if not isinstance(budget, (int, float)): + print("Invalid entry. Please enter a number.") + exit() + + def change(self, budget): + return (budget - self.price) + + def buy(self, budget): + + self.budget_check(budget) + + if budget >= self.price: + print(f'You can cop some {self.name}') + + if budget == self.price: + print("You have enough mony") + + else: + print(f'You can buy these shoes and have {self.change(budget)}$ left over') + + exit("Goodbye ^_^ ") \ No newline at end of file diff --git a/python/project/__pycache__/Shoes.cpython-310.pyc b/python/project/__pycache__/Shoes.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..89e612a3f19d644d487815f39c69d4e03ff9a075 GIT binary patch literal 1149 zcmZuw&2AGh5VpNP-EPy+Ru$sFVUfxq5;Sl}2#G_*C5jX-xDdqd=Fdi16k4~iHV_0wnC0^G9ov0&~qBMOlG3-riDyQ7Z4K7S6q8*q!9& zrhJt7lZu}RV_)Br0L7hF9H*H`&u|trin}zRA$9-Md+qD)8r^&0ZF|ri+jB~uz*`i` zd(>84b%FmM+E25jJQ0sTrO`H|b*F`E759L!@V1o4z%0o%fPIJZSx9>3sh0)@4d9(i zas|_It6}OXXso2%0?q+n7kw`Ycds1V0*`xm-ZsG>)VrT#6{SfTrE(r=n3kyCM^ToX zV=H8Jl0`FFF6w7%!%4M>OeUaH8V5N_O5R%6TL)1grY4f-Le-rkDfwg}qT~2D>iKF1 zp3|18gPfh!UF5crJXAUdknl%pbPZX^b|_H#*y%9$SG~Dz+G5b#z`4bb5ywp!$1};R z0{KoHf3A|E)u>GbvT0ac41K3t_+b=|g`z+(J&mmnNWcOw@H&o_51`kmf5@>3-n7VX K(ZY6nkNpL*!1Ejc literal 0 HcmV?d00001 diff --git a/python/project/purchase.py b/python/project/purchase.py new file mode 100644 index 0000000..49fd399 --- /dev/null +++ b/python/project/purchase.py @@ -0,0 +1,13 @@ +from Shoes import Shoes + +low = Shoes('And 1s', 30) +medium = Shoes('Air Force 1s', 120) +high = Shoes('Off Whites', 400) + +try: + budget = float(input('What is your budget? ')) +except ValueError: + exit('Please enter a number') + +for shoes in [high, medium, low]: + shoes.buy(budget)