Skip to content

Commit

Permalink
Merge branch 'master' of github.com:realpython/materials into pyproje…
Browse files Browse the repository at this point in the history
…ct-toml
  • Loading branch information
iansedano committed Dec 30, 2024
2 parents ca9d33b + 21c0a2e commit c0cf665
Show file tree
Hide file tree
Showing 123 changed files with 2,066 additions and 282 deletions.
9 changes: 9 additions & 0 deletions basic-input-output-in-python/README.md
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
```
26 changes: 26 additions & 0 deletions basic-input-output-in-python/adventure_game.py
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")
2 changes: 2 additions & 0 deletions basic-input-output-in-python/greeter.py
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!")
9 changes: 9 additions & 0 deletions basic-input-output-in-python/guess_the_number.py
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)
4 changes: 4 additions & 0 deletions basic-input-output-in-python/improved_input.py
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)
36 changes: 16 additions & 20 deletions celery-async-tasks/source_code_final/requirements.txt
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
36 changes: 16 additions & 20 deletions celery-async-tasks/source_code_initial/requirements.txt
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
9 changes: 0 additions & 9 deletions concurrency-overview/README.md

This file was deleted.

21 changes: 0 additions & 21 deletions concurrency-overview/cpu_mp.py

This file was deleted.

20 changes: 0 additions & 20 deletions concurrency-overview/cpu_non_concurrent.py

This file was deleted.

21 changes: 0 additions & 21 deletions concurrency-overview/cpu_threading.py

This file was deleted.

35 changes: 0 additions & 35 deletions concurrency-overview/io_mp.py

This file was deleted.

17 changes: 0 additions & 17 deletions concurrency-overview/race_condition.py

This file was deleted.

35 changes: 0 additions & 35 deletions concurrency-overview/requirements.txt

This file was deleted.

46 changes: 46 additions & 0 deletions django-user-management/README.md
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.
3 changes: 3 additions & 0 deletions django-user-management/requirements.txt
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
22 changes: 22 additions & 0 deletions django-user-management/user_auth_intro/manage.py
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 django-user-management/user_auth_intro/user_auth_intro/asgi.py
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()
Loading

0 comments on commit c0cf665

Please sign in to comment.