Created
December 19, 2024 19:09
-
-
Save jymchng/e710cc588b74b417630addba1f7a3df8 to your computer and use it in GitHub Desktop.
Python Playground Code
This file contains hidden or 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
import os, sys # Possible to import most packages; go to [Installed Packages] tab, type in the names | |
# delimited by comma of the packages you want to install. | |
# Click on [Add Package(s)] | |
# Then import those packages, e.g. import attrs | |
import logging | |
from logging import getLogger | |
logger = getLogger(__name__) | |
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s', stream=sys.stdout) | |
# Click on the dropdown button and choose [Format], then click on the [Format] button | |
# to see how the `fibonacci` function definition is reformatted. | |
# Define a function that takes an integer n and returns the nth number in the Fibonacci | |
# sequence. | |
def fibonacci(n): | |
"""Compute the nth number in the Fibonacci sequence.""" | |
x = 1 | |
if n == 0: return 0 | |
elif n == 1: return 1 | |
else: return fibonacci(n - 1) + fibonacci(n - 2) | |
# Use a for loop to generate and print the first 10 numbers in the Fibonacci sequence. | |
for i in range(10): | |
print(fibonacci(i)) | |
logger.info(f"`fibonacci({i})` = {fibonacci(i)}") | |
# Click on the dropdown button and choose [Test], then click on the [Test] button | |
# to see how you can use pytest on this playground. | |
def test_fibonacci(): | |
for i in range(10): | |
assert fibonacci(i) == fibonacci(i) |
This file contains hidden or 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
# This is an empty file |
This file contains hidden or 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
>>> | |
0 | |
2024-12-20 02:45:41,336 INFO [<exec>:27] `fibonacci(0)` = 0 | |
1 | |
2024-12-20 02:45:41,337 INFO [<exec>:27] `fibonacci(1)` = 1 | |
1 | |
2024-12-20 02:45:41,337 INFO [<exec>:27] `fibonacci(2)` = 1 | |
2 | |
2024-12-20 02:45:41,338 INFO [<exec>:27] `fibonacci(3)` = 2 | |
3 | |
2024-12-20 02:45:41,339 INFO [<exec>:27] `fibonacci(4)` = 3 | |
5 | |
2024-12-20 02:45:41,339 INFO [<exec>:27] `fibonacci(5)` = 5 | |
8 | |
2024-12-20 02:45:41,340 INFO [<exec>:27] `fibonacci(6)` = 8 | |
13 | |
2024-12-20 02:45:41,340 INFO [<exec>:27] `fibonacci(7)` = 13 | |
21 | |
2024-12-20 02:45:41,342 INFO [<exec>:27] `fibonacci(8)` = 21 | |
34 | |
2024-12-20 02:45:41,342 INFO [<exec>:27] `fibonacci(9)` = 34 | |
This file contains hidden or 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
import os, sys # Possible to import most packages; go to [Installed Packages] tab, type in the names | |
# delimited by comma of the packages you want to install. | |
# Click on [Add Package(s)] | |
# Then import those packages, e.g. import attrs | |
import logging | |
from logging import getLogger | |
logger = getLogger(__name__) | |
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s', stream=sys.stdout) | |
# Click on the dropdown button and choose [Format], then click on the [Format] button | |
# to see how the `fibonacci` function definition is reformatted. | |
# Define a function that takes an integer n and returns the nth number in the Fibonacci | |
# sequence. | |
def fibonacci(n): | |
"""Compute the nth number in the Fibonacci sequence.""" | |
x = 1 | |
if n == 0: return 0 | |
elif n == 1: return 1 | |
else: return fibonacci(n - 1) + fibonacci(n - 2) | |
# Use a for loop to generate and print the first 10 numbers in the Fibonacci sequence. | |
for i in range(10): | |
print(fibonacci(i)) | |
logger.info(f"`fibonacci({i})` = {fibonacci(i)}") | |
# Click on the dropdown button and choose [Test], then click on the [Test] button | |
# to see how you can use pytest on this playground. | |
def test_fibonacci(): | |
for i in range(10): | |
assert fibonacci(i) == fibonacci(i) |
This file contains hidden or 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
>>> | |
0 | |
2024-12-20 02:45:27,689 INFO [<exec>:36] `fibonacci(0)` = 0 | |
1 | |
2024-12-20 02:45:27,694 INFO [<exec>:36] `fibonacci(1)` = 1 | |
1 | |
2024-12-20 02:45:27,696 INFO [<exec>:36] `fibonacci(2)` = 1 | |
2 | |
2024-12-20 02:45:27,696 INFO [<exec>:36] `fibonacci(3)` = 2 | |
3 | |
2024-12-20 02:45:27,697 INFO [<exec>:36] `fibonacci(4)` = 3 | |
5 | |
2024-12-20 02:45:27,697 INFO [<exec>:36] `fibonacci(5)` = 5 | |
8 | |
2024-12-20 02:45:27,697 INFO [<exec>:36] `fibonacci(6)` = 8 | |
13 | |
2024-12-20 02:45:27,697 INFO [<exec>:36] `fibonacci(7)` = 13 | |
21 | |
2024-12-20 02:45:27,699 INFO [<exec>:36] `fibonacci(8)` = 21 | |
34 | |
2024-12-20 02:45:27,699 INFO [<exec>:36] `fibonacci(9)` = 34 | |
This file contains hidden or 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
import os, sys # Possible to import most packages; go to [Installed Packages] tab, type in the names | |
# delimited by comma of the packages you want to install. | |
# Click on [Add Package(s)] | |
# Then import those packages, e.g. import attrs | |
import logging | |
from logging import getLogger | |
logger = getLogger(__name__) | |
logging.basicConfig( | |
level=logging.INFO, | |
format="%(asctime)s %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s", | |
stream=sys.stdout, | |
) | |
# Click on the dropdown button and choose [Format], then click on the [Format] button | |
# to see how the `fibonacci` function definition is reformatted. | |
# Define a function that takes an integer n and returns the nth number in the Fibonacci | |
# sequence. | |
def fibonacci(n): | |
"""Compute the nth number in the Fibonacci sequence.""" | |
x = 1 | |
if n == 0: | |
return 0 | |
elif n == 1: | |
return 1 | |
else: | |
return fibonacci(n - 1) + fibonacci(n - 2) | |
# Use a for loop to generate and print the first 10 numbers in the Fibonacci sequence. | |
for i in range(10): | |
print(fibonacci(i)) | |
logger.info(f"`fibonacci({i})` = {fibonacci(i)}") | |
# Click on the dropdown button and choose [Test], then click on the [Test] button | |
# to see how you can use pytest on this playground. | |
def test_fibonacci(): | |
for i in range(10): | |
assert fibonacci(i) == fibonacci(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment