This file contains 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
def is_palindrome(number: int) -> bool: | |
"""Return True if number is palindrome integer. | |
Designed to be efficient with integers of arbitrary length. | |
""" | |
if number < 0: | |
return False | |
if number < 10: | |
return True | |
reversed = 0 | |
while number > reversed: |
This file contains 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
"""Tic-Tac-Toe | |
A simple implementation in (mostly) procedural style. | |
""" | |
import sys | |
from random import choice | |
from typing import TypeAlias | |
Board: TypeAlias = list[list[str]] |
This file contains 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
"""Roulette wheel simulation.""" | |
from random import randrange | |
def wheel_spin() -> int: | |
"""Return result of roulette wheel spin. | |
Returns | |
------- |
This file contains 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
"""Explore the surprising probabilities of the "Birthday Paradox". | |
Idea inspired by The Big Book of Small Python Projects by Al Sweigart. | |
https://inventwithpython.com/bigbookpython/project2.html | |
This version runs much faster than the version in the book, and so | |
can handle much larger numbers of people. | |
The main optimisations are: | |
1. `get_birthdays_till_match` exits early when a match is found. |
This file contains 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
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
""" | |
Record Parts: | |
============= | |
A demonstration Python application controlling Audacity to make a | |
sequence of recordings. There will inevitably be short breaks between | |
each recording due to the time required to Export, clean up and start |
This file contains 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
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
"""Automate Audacity via mod-script-pipe. | |
Pipe Client may be used as a command-line script to send commands to | |
Audacity via the mod-script-pipe interface, or loaded as a module. | |
Requires Python 3. | |
(Python 2.7 is now obsolete, so no longer supported) |