From 9c4b66c4ce9338202e1be89f65249a7b72657f43 Mon Sep 17 00:00:00 2001 From: acid Date: Tue, 26 Jan 2021 20:54:08 +0000 Subject: [PATCH] First update with working code --- .gitignore | 157 +++++++++++++++++++++++++++++++++++++++++++++++++++++ ghost.py | 45 +++++++++++++++ 2 files changed, 202 insertions(+) create mode 100644 .gitignore create mode 100644 ghost.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..594cd06 --- /dev/null +++ b/.gitignore @@ -0,0 +1,157 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/python,venv +# Edit at https://www.toptal.com/developers/gitignore?templates=python,venv + +### Python ### +# 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/ +pytestdebug.log + +# 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/ +doc/_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/ +pythonenv* + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# profiling data +.prof + +### venv ### +# Virtualenv +# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/ +[Bb]in +[Ii]nclude +[Ll]ib +[Ll]ib64 +[Ll]ocal +[Ss]cripts +pyvenv.cfg +pip-selfcheck.json + +# End of https://www.toptal.com/developers/gitignore/api/python,venv diff --git a/ghost.py b/ghost.py new file mode 100644 index 0000000..5a919f9 --- /dev/null +++ b/ghost.py @@ -0,0 +1,45 @@ +from random import randint + +# Keep variable initialisation away from any statements that 'do' something, like printing +score = 0 + +# This is a function to help prevent code duplication +# We pass in the score variable in brackets so that the function can use it +def print_score(score): + # Here we use an 'f-string', note the f before the quotes + # That lets us use variables inside curly brackets + print(f"Your score is: {score}") + + + +# We don't need to track this as we will loop until we break +while True: + + # Call our custom function to print the scor + print_score(score) + + # This is one way to do a multi-line string + print("""Three doors ahead... + A ghost behind one. + Which door do you open?""") + + # We don't need to store the input or ghost door so can compute them at the time of use + # We test the negative (!=), just to flip the order for aesthetics + if int(input('Choose door 1, 2, or 3: ')) != randint(1,3): + + # An alternative way to print more than one line, with \n + print ('No ghost!\n You enter the next room') + + # This is another way to increment a variable + score += 1 + + # Else in this case means that the input WAS the same as the random int + else: + # this will break us out of the while True loop + break + +# If we are here then we've lost +print ('GHOST!\nRun away!\nGame Over') +print_score(score) + +