School Commit Init

This commit is contained in:
2024-08-31 12:07:21 +03:00
commit 0b130ee18c
2801 changed files with 4720552 additions and 0 deletions
@@ -0,0 +1,129 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
@@ -0,0 +1,2 @@
# commit & push your solution to Test 1 to this repository
@@ -0,0 +1,46 @@
def add_flight(list_of_flights,code,duration,dep_city,dest_city):
"""
:params:
list_of_flights - list[dict...]
code - str
duration - int
dep_city - str
dest_city - str
:return:
None
The function takes in a list of flights and the code, duration, departure city and destination city of a flight
It then checks if there exists already a flight with the same code as the one introduce, if so raises a ValueError
Else it append a new flight as a dictionary into the list_of_flights list
"""
for flight in list_of_flights:
if flight["code"]==code:
raise ValueError
flight={
"code":code,
"duration":duration,
"dep_city":dep_city,
"dest_city":dest_city
}
list_of_flights.append(flight)
def modify_flight(list_of_flights,code,new_duration):
for flight in list_of_flights:
if flight["code"]==code:
flight["duration"]=new_duration
return
raise ValueError
def reroute_flight(list_of_flights,dest_city,new_dest_city):
for flight in list_of_flights:
if flight["dest_city"]==dest_city:
flight["dest_city"]=new_dest_city
def show_flight(list_of_flights,dep_city):
new_flights = [flight for flight in list_of_flights if flight["dep_city"]==dep_city]
return sorted(new_flights,key=get_duration)
def print_nicely(flight):
print("Code: {} | Duration: {} | Departure City: {} | Destination City: {} \n".format(flight["code"],flight["duration"],flight["dep_city"],flight["dest_city"]))
def get_duration(flight):
return flight["duration"]
@@ -0,0 +1,4 @@
from ui import UI
if __name__=="__main__":
UI()
@@ -0,0 +1,20 @@
from functions import add_flight
def test_add():
l=[]
add_flight(l,"2421",50,"Cluj-Napoca","Istambul")
assert l==[{
"code":"2421",
"duration":50,
"dep_city":"Cluj-Napoca",
"dest_city":"Istambul"
}]
print("Added correctly")
try:
add_flight(l,"2421",50,"Cluj-Napoca","Istambul")
except:
print("Error raised correctly")
print("It works")
if __name__=="__main__":
test_add()
@@ -0,0 +1,103 @@
import re
from functions import *
def UI():
list_of_flights=[
{
"code":"0735G",
"duration":40,
"dep_city":"Cluj-Napoca",
"dest_city":"Bucuresti"
},
{
"code":"07378",
"duration":60,
"dep_city":"Bucuresti",
"dest_city":"Istambul"
},
{
"code":"AFNVA",
"duration":100,
"dep_city":"Bucuresti",
"dest_city":"Tokyo"
},
{
"code":"BIV73",
"duration":20,
"dep_city":"Bucuresti",
"dest_city":"Cluj-Napoca"
},
{
"code":"KS23B",
"duration":60,
"dep_city":"Istambul",
"dest_city":"Bucuresti"
}
]
while True:
print("""
1.Add a flight
2.Modify a flight
3.Reroute flights
4.Show flights
5.Exit
""")
i=input(">")
match i:
case "1":
code=input("Please enter a code: ")
if len(code)<3:
print("Invalid code")
continue
duration=input("Please enter a duration: ")
if not re.match("\d+",duration) or int(duration)<20:
print("Invalid duration")
continue
dep_city=input("Please enter a departure city: ")
if len(dep_city)<3:
print("Invalid departure city")
continue
dest_city=input("Please enter a destination city: ")
if len(dest_city)<3:
print("Invalid destination city")
continue
try:
add_flight(list_of_flights,code,int(duration),dep_city,dest_city)
except:
print("Flight code already registered")
case "2":
code=input("Please enter a code: ")
if len(code)<3:
print("Invalid code")
continue
duration=input("Please enter a duration: ")
if not re.match("\d+",duration) or int(duration)<20:
print("Invalid duration")
continue
try:
modify_flight(list_of_flights,code,duration)
except:
print("Invalid flight")
case "3":
dest_city=input("Please enter a destination city: ")
if len(dest_city)<3:
print("Invalid destination city")
continue
new_dest_city=input("Please enter a new destination city: ")
if len(new_dest_city)<3:
print("Invalid destination city")
continue
reroute_flight(list_of_flights,dest_city,new_dest_city)
case "4":
dep_city=input("Please enter a departure city: ")
if len(dep_city)<3:
print("Invalid departure city")
continue
flights=show_flight(list_of_flights,dep_city)
for flight in flights:
print_nicely(flight)
case "5":
break
case _:
print("Wrong Command")