Skip to content

Commit 07d6ccb

Browse files
Merge branch 'master' into celery-refresh
2 parents af9990d + bd032b2 commit 07d6ccb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+633
-351
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Basic Input and Output in Python
2+
3+
This folder contains the code examples for the Real Python tutorial [Basic Input and Output in Python](https://realpython.com/python-input-output/).
4+
5+
You can run all of the scripts directly by specifying their name:
6+
7+
```sh
8+
$ python <filename>.py
9+
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import random
2+
3+
health = 5
4+
enemy_health = 3
5+
6+
while health > 0 and enemy_health > 0:
7+
# Normalize input to handle extra spaces and case variations.
8+
action = input("Attack or Run? ").strip().lower()
9+
if action not in {"attack", "run"}:
10+
print("Invalid choice. Please type 'Attack' or 'Run'.")
11+
continue
12+
13+
if action == "attack":
14+
enemy_health -= 1
15+
print("You hit the enemy!")
16+
# Implement a 50% chance that the enemy strikes back.
17+
enemy_attacks = random.choice([True, False])
18+
if enemy_attacks:
19+
health -= 2
20+
print("The enemy strikes back!")
21+
else:
22+
print("You ran away!")
23+
break
24+
print(f"Your health: {health}, Enemy health: {enemy_health}")
25+
26+
print("Victory!" if enemy_health <= 0 else "Game Over")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
name = input("Please enter your name: ")
2+
print("Hello", name, "and welcome!")
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import random
2+
3+
number = random.randint(1, 10)
4+
guess = int(input("Guess a number between 1 and 10: "))
5+
6+
if guess == number:
7+
print("You got it!")
8+
else:
9+
print("Sorry, the number was", number)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import readline # noqa F401
2+
3+
while (user_input := input("> ")).lower() != "exit":
4+
print("You entered:", user_input)

concurrency-overview/README.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

concurrency-overview/cpu_mp.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

concurrency-overview/cpu_non_concurrent.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

concurrency-overview/cpu_threading.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

concurrency-overview/io_mp.py

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)