Skip to content

Commit 2931372

Browse files
authored
Merge branch 'master' into fix/update-readme-badge
2 parents aac3037 + 2dc7bfb commit 2931372

File tree

558 files changed

+3570
-152
lines changed

Some content is hidden

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

558 files changed

+3570
-152
lines changed

build-a-rest-api-frontend/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Build a Front End for a REST API
22

3-
This repository contains code related to the Real Python tutorial on [building a front end for a REST API](https://realpython.com/build-a-rest-api-frontend/).
3+
This repository contains code related to the Real Python tutorial on [building a front end for a REST API](https://realpython.com/flask-javascript-frontend-for-rest-api/).
44

55
## Setup
66

chatgpt-mentor/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# ChatGPT: Your Personal Python Coding Mentor
2+
3+
This repository holds the code used in the Real Python [ChatGPT: Your Personal Python Coding Mentor](https://realpython.com/chatgpt-coding-mentor-python/) tutorial, along with a few additional files.
4+
5+
## Run the Scripts
6+
7+
All example scripts should run on any Python version >=3.6 by executing the files with the interpreter:
8+
9+
```console
10+
$ python filename.py
11+
```
12+
13+
To play with the different implementations of FizzBuzz, you can load the files interactively into a REPL using the `-i` flag.
14+
15+
## Prompts
16+
17+
The repository also contains an additional file called [prompts.md](prompts.md) that lists all the prompts used in the tutorial. If you want to try them in your own ChatGPT conversations, then you can copy the prompts from that file.
18+
19+
## Author
20+
21+
- **Martin Breuss**, E-mail: [[email protected]]([email protected])
22+
23+
## License
24+
25+
Distributed under the MIT license. See [`LICENSE`](../LICENSE) for more information.

chatgpt-mentor/cheatsheet.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
| Syntax | Example | Description |
2+
| --- | --- | --- |
3+
| Variables | `x = 5` | Assign a value to a variable |
4+
| Conditionals | `if x == 5:`<br>&nbsp;&nbsp;&nbsp;&nbsp;`print("x is 5")` | Execute code only if a condition is met |
5+
| Loops | `for i in range(5):`<br>&nbsp;&nbsp;&nbsp;&nbsp;`print(i)` | Execute code repeatedly |
6+
| Functions | `def my_func(x, y):`<br>&nbsp;&nbsp;&nbsp;&nbsp;`return x + y` | Reusable block of code that performs a specific task |
7+
| Classes | `class MyClass:`<br>&nbsp;&nbsp;&nbsp;&nbsp;`def __init__(self, x):`<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`self.x = x`<br>&nbsp;&nbsp;&nbsp;&nbsp;`def my_method(self):`<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`print(self.x)` | Blueprint for creating objects with specific attributes and methods |
8+
| Imports | `import math`<br>`print(math.sqrt(4))` | Use code from another module or package |
9+
| Exception handling | `try:`<br>&nbsp;&nbsp;&nbsp;&nbsp;`x = 1 / 0`<br>`except ZeroDivisionError:`<br>&nbsp;&nbsp;&nbsp;&nbsp;`print("Cannot divide by zero")` | Handle errors that might occur during program execution |
10+
| Boolean operators | `and`, `or`, `not` | Operators that operate on boolean values |
11+
| Math operators | `+`, `-`, `*`, `/`, `//`, `%`, `**` | Operators that perform mathematical operations |
12+
| Comparison operators | `==`, `!=`, `<`, `>`, `<=`, `>=` | Operators that compare values |
13+
| Comprehensions | `[i**2 for i in range(5)]` | Concise syntax for creating lists, dictionaries, and sets |

chatgpt-mentor/cheatsheet.pdf

72 KB
Binary file not shown.

chatgpt-mentor/fizzbuzz.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def fizzbuzz(number):
2+
if number % 3 == 0:
3+
return "fizz"
4+
elif number % 5 == 0:
5+
return "buzz"
6+
elif number % 15 == 0:
7+
return "fizz buzz"
8+
else:
9+
return number
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def fizzbuzz(n):
2+
for i in range(1, n + 1):
3+
if i % 15 == 0:
4+
print("fizz buzz")
5+
elif i % 3 == 0:
6+
print("fizz")
7+
elif i % 5 == 0:
8+
print("buzz")
9+
else:
10+
print(i)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def fizzbuzz(n):
2+
result = [
3+
"fizz buzz"
4+
if i % 15 == 0
5+
else "fizz"
6+
if i % 3 == 0
7+
else "buzz"
8+
if i % 5 == 0
9+
else i
10+
for i in range(1, n + 1)
11+
]
12+
return result
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def fizzbuzz(n):
2+
return (
3+
"fizz buzz"
4+
if i % 15 == 0
5+
else "fizz"
6+
if i % 3 == 0
7+
else "buzz"
8+
if i % 5 == 0
9+
else i
10+
for i in range(1, n + 1)
11+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def fizzbuzz(n):
2+
mapping = {3: "fizz", 5: "buzz", 15: "fizz buzz"}
3+
for i in range(1, n + 1):
4+
output = ""
5+
for key in mapping:
6+
if i % key == 0:
7+
output += mapping[key]
8+
if output == "":
9+
output = i
10+
print(output)

chatgpt-mentor/guess_final.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import random
2+
3+
4+
def guess_the_number(low: int = 1, high: int = 100) -> int:
5+
"""
6+
Plays a guessing game where the user must guess a random number between
7+
`low` and `high`. Returns the randomly generated number.
8+
9+
Args:
10+
low (int): The lowest possible number in the range (default 1).
11+
high (int): The highest possible number in the range (default 100).
12+
13+
Returns:
14+
int: The randomly generated number.
15+
16+
"""
17+
random_number = random.randint(low, high)
18+
user_guess = None
19+
20+
while user_guess != random_number:
21+
user_guess = int(input(f"Guess a number between {low} and {high}: "))
22+
if user_guess < random_number:
23+
print("Your guess is too low. Try again!")
24+
elif user_guess > random_number:
25+
print("Your guess is too high. Try again!")
26+
else:
27+
print("Congratulations, you guessed the number correctly!")
28+
29+
return random_number

0 commit comments

Comments
 (0)