First update with working code
This commit is contained in:
157
.gitignore
vendored
Normal file
157
.gitignore
vendored
Normal file
@@ -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
|
||||||
45
ghost.py
Normal file
45
ghost.py
Normal file
@@ -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)
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user