Skip to content

Commit ab61c3c

Browse files
authored
Merge pull request #355 from realpython/python-repl
Sample code for the REPL article
2 parents c115d9c + c9d5442 commit ab61c3c

File tree

5 files changed

+34
-0
lines changed

5 files changed

+34
-0
lines changed

python-repl/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# The Python Standard REPL: Try Out Code and Ideas Quickly
2+
3+
This folder provides the code examples for the Real Python tutorial [The Python Standard REPL: Try Out Code and Ideas Quickly](https://realpython.com/python-repl/).

python-repl/calculations.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def add(a, b):
2+
return a + b
3+
4+
5+
def sub(a, b):
6+
return a - b

python-repl/greeting.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def greet(name="World"):
2+
print(f"Hello, {name}!")
3+
4+
5+
name = input("What is your name? ")
6+
7+
greet(name)

python-repl/greeting_upper.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def greet(name="World", upper=False):
2+
greeting = f"Hello, {name}!"
3+
if upper:
4+
greeting = greeting.upper()
5+
print(greeting)

python-repl/sample.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def read_data():
2+
# Read data from a file or database...
3+
return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
4+
5+
6+
sample = read_data()
7+
8+
9+
def mean(data):
10+
return sum(data) / len(data)
11+
12+
13+
average = mean(sample)

0 commit comments

Comments
 (0)