Skip to content

Instantly share code, notes, and snippets.

verses = ["a Partridge in a Pear Tree", "Two Turtle Doves", "Three French Hens", "Four Calling Birds",
"Five Gold Rings", "Six Geese-a-Laying", "Seven Swans-a-Swimming", "Eight Maids-a-Milking",
"Nine Ladies Dancing", "Ten Lords-a-Leaping", "Eleven Pipers Piping", "Twelve Drummers Drumming"]
days = {index - 1: ', '.join(reversed(verses[:index - 1])) for index, verse in enumerate(verses)}
def get_day(day):
return "On the {} day of Christmas my true love sent to me,".format(day) + days[day]
def get_presents(start, end=None):
return sum(range(start, end + 1)) if end else sum(range(start))
import winsound
sound_path = r""
def play_sound(path):
winsound.PlaySound(path, winsound.SND_FILENAME)
print("Prime #s from 1 to 1000")
def is_prime(n):
for i in range(3, n):
if n % i == 0:
return False
return True
for number in range(1000):
import time
def get_contents(file_name):
return open(file_name).readlines() # Return a list of the lines of text
last_version = get_contents('test.txt')
while True:
current_version = get_contents('test.txt')
if last_version != current_version: # Has it changed from what it was before?
def main():
while True:
how_many_loops = input("How many grades will you be entering? ")
if '.' not in how_many_loops:
for _ in range(int(how_many_loops)):
while True:
score = int(input("Please enter a grade between 0 and 100: "))
if score > 100 or score < 0:
print('Your number is out of range!', end=' ')
continue
How many grades will you be entering? 3
Please enter a grade between 0 and 100: 2000
Your number is out of range! Please enter a grade between 0 and 100: 2000
Your number is out of range! Please enter a grade between 0 and 100: 2000
Your number is out of range! Please enter a grade between 0 and 100: 2000
Your number is out of range! Please enter a grade between 0 and 100: 2
Please enter a grade between 0 and 100: 3
Please enter a grade between 0 and 100: 4
def is_prime(number):
for x in range(2, number):
if number % x == 0:
return False
return True
for n in range(1, 101):
if is_prime(n):
print(n, 'is prime')
import praw
def _get_question_comment(comment):
if comment.is_root:
return
parent_comment = r.get_info(thing_id=comment.parent_id)
if parent_comment.is_root:
return parent_comment, comment
import random
JAPANESE_CHARACTERS = [
['いちまい', 'にまい', 'さんまい', 'よんまい', 'ごまい', 'ろくまい', 'ななまい', 'はちまい', 'きゅうまい', 'じゅうまい'],
['いっさつ', 'にさつ', 'さんさつ', 'よんさつ', 'ごさつ', 'ろくさつ', 'ななさつ', 'はっさつ', 'きゅうさつ', 'じゅさつ'],
['いっぽん', 'にほん', 'さんぼん', 'よんまい', 'ごまい', 'ろくまい', 'ななまい', 'はちまい', 'きゅうまい', 'じゅうまい'],
['ひとつ', 'ふたつ', 'みっつ', 'よっつ', 'いつつ', 'むっつ', 'ななつ', 'やっつ', 'ここのつ', 'とお']
]
answer_selections = ["a", "b", "c", "d"]
from flask import json
import websocket
def get_bar(time, max_elements):
return '[{}{}]'.format('|' * time, ' ' * (max_elements - time))
def on_message(ws, message):