-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:realpython/materials into pyproje…
…ct-toml
- Loading branch information
Showing
123 changed files
with
2,066 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Basic Input and Output in Python | ||
|
||
This folder contains the code examples for the Real Python tutorial [Basic Input and Output in Python](https://realpython.com/python-input-output/). | ||
|
||
You can run all of the scripts directly by specifying their name: | ||
|
||
```sh | ||
$ python <filename>.py | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import random | ||
|
||
health = 5 | ||
enemy_health = 3 | ||
|
||
while health > 0 and enemy_health > 0: | ||
# Normalize input to handle extra spaces and case variations. | ||
action = input("Attack or Run? ").strip().lower() | ||
if action not in {"attack", "run"}: | ||
print("Invalid choice. Please type 'Attack' or 'Run'.") | ||
continue | ||
|
||
if action == "attack": | ||
enemy_health -= 1 | ||
print("You hit the enemy!") | ||
# Implement a 50% chance that the enemy strikes back. | ||
enemy_attacks = random.choice([True, False]) | ||
if enemy_attacks: | ||
health -= 2 | ||
print("The enemy strikes back!") | ||
else: | ||
print("You ran away!") | ||
break | ||
print(f"Your health: {health}, Enemy health: {enemy_health}") | ||
|
||
print("Victory!" if enemy_health <= 0 else "Game Over") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
name = input("Please enter your name: ") | ||
print("Hello", name, "and welcome!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import random | ||
|
||
number = random.randint(1, 10) | ||
guess = int(input("Guess a number between 1 and 10: ")) | ||
|
||
if guess == number: | ||
print("You got it!") | ||
else: | ||
print("Sorry, the number was", number) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import readline # noqa F401 | ||
|
||
while (user_input := input("> ")).lower() != "exit": | ||
print("You entered:", user_input) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,18 @@ | ||
amqp==5.1.1 | ||
asgiref==3.5.2 | ||
async-timeout==4.0.2 | ||
billiard==3.6.4.0 | ||
celery==5.2.7 | ||
click==8.1.3 | ||
click-didyoumean==0.3.0 | ||
amqp==5.3.1 | ||
asgiref==3.8.1 | ||
billiard==4.2.1 | ||
celery==5.4.0 | ||
click==8.1.7 | ||
click-didyoumean==0.3.1 | ||
click-plugins==1.1.1 | ||
click-repl==0.2.0 | ||
Deprecated==1.2.13 | ||
Django==4.0.6 | ||
kombu==5.2.4 | ||
packaging==21.3 | ||
prompt-toolkit==3.0.30 | ||
pyparsing==3.0.9 | ||
pytz==2022.1 | ||
redis==4.3.4 | ||
click-repl==0.3.0 | ||
Django==5.1.3 | ||
kombu==5.4.2 | ||
prompt_toolkit==3.0.48 | ||
python-dateutil==2.9.0.post0 | ||
redis==5.2.0 | ||
six==1.16.0 | ||
sqlparse==0.4.2 | ||
vine==5.0.0 | ||
wcwidth==0.2.5 | ||
wrapt==1.14.1 | ||
sqlparse==0.5.2 | ||
tzdata==2024.2 | ||
vine==5.1.0 | ||
wcwidth==0.2.13 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,18 @@ | ||
amqp==5.1.1 | ||
asgiref==3.5.2 | ||
async-timeout==4.0.2 | ||
billiard==3.6.4.0 | ||
celery==5.2.7 | ||
click==8.1.3 | ||
click-didyoumean==0.3.0 | ||
amqp==5.3.1 | ||
asgiref==3.8.1 | ||
billiard==4.2.1 | ||
celery==5.4.0 | ||
click==8.1.7 | ||
click-didyoumean==0.3.1 | ||
click-plugins==1.1.1 | ||
click-repl==0.2.0 | ||
Deprecated==1.2.13 | ||
Django==4.0.6 | ||
kombu==5.2.4 | ||
packaging==21.3 | ||
prompt-toolkit==3.0.30 | ||
pyparsing==3.0.9 | ||
pytz==2022.1 | ||
redis==4.3.4 | ||
click-repl==0.3.0 | ||
Django==5.1.3 | ||
kombu==5.4.2 | ||
prompt_toolkit==3.0.48 | ||
python-dateutil==2.9.0.post0 | ||
redis==5.2.0 | ||
six==1.16.0 | ||
sqlparse==0.4.2 | ||
vine==5.0.0 | ||
wcwidth==0.2.5 | ||
wrapt==1.14.1 | ||
sqlparse==0.5.2 | ||
tzdata==2024.2 | ||
vine==5.1.0 | ||
wcwidth==0.2.13 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Get Started With Django User Management | ||
|
||
Follow the [step-by-step instructions](https://realpython.com/django-user-management/) on Real Python. | ||
|
||
## Setup | ||
|
||
You can run the provided example project on your local machine by following the steps outlined below. | ||
|
||
Create a new virtual environment: | ||
|
||
```bash | ||
$ python3 -m venv venv/ | ||
``` | ||
|
||
Activate the virtual environment: | ||
|
||
```bash | ||
$ source venv/bin/activate | ||
``` | ||
|
||
Install the dependencies for this project if you haven't installed them yet: | ||
|
||
```bash | ||
(venv) $ python -m pip install -r requirements.txt | ||
``` | ||
|
||
Navigate into the project's directory: | ||
|
||
```bash | ||
(venv) $ cd user_auth_intro/ | ||
``` | ||
|
||
Make and apply the migrations for the project to build your local database: | ||
|
||
```bash | ||
(venv) $ python manage.py makemigrations | ||
(venv) $ python manage.py migrate | ||
``` | ||
|
||
Run the Django development server: | ||
|
||
```bash | ||
(venv) $ python manage.py runserver | ||
``` | ||
|
||
Navigate to `http://localhost:8000/dashboard` to see the project in action. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
asgiref==3.8.1 | ||
Django==5.1.3 | ||
sqlparse==0.5.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env python | ||
"""Django's command-line utility for administrative tasks.""" | ||
import os | ||
import sys | ||
|
||
|
||
def main(): | ||
"""Run administrative tasks.""" | ||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "user_auth_intro.settings") | ||
try: | ||
from django.core.management import execute_from_command_line | ||
except ImportError as exc: | ||
raise ImportError( | ||
"Couldn't import Django. Are you sure it's installed and " | ||
"available on your PYTHONPATH environment variable? Did you " | ||
"forget to activate a virtual environment?" | ||
) from exc | ||
execute_from_command_line(sys.argv) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Empty file.
16 changes: 16 additions & 0 deletions
16
django-user-management/user_auth_intro/user_auth_intro/asgi.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
ASGI config for user_auth_intro project. | ||
It exposes the ASGI callable as a module-level variable named ``application``. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/5.1/howto/deployment/asgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.asgi import get_asgi_application | ||
|
||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "user_auth_intro.settings") | ||
|
||
application = get_asgi_application() |
Oops, something went wrong.