Skip to content

Instantly share code, notes, and snippets.

View AnnikaNoren's full-sized avatar

Annika Noren AnnikaNoren

View GitHub Profile
def disarm(num):
temp = 0
num_list = [int(x) for x in str(num)]
for i, j in enumerate(num_list):
temp += j ** (i+1)
if temp == num:
print("The number", num, "is a disarmuim")
else:
def disarm(num):
num_str = str(num)
count = len(num_str)
temp = 0
for i in range(0, count):
temp += int(num_str[i]) ** int((i+1))
if temp == num:
print("The number", num, "is a disarmuim")
else:
def has_friday_13(month, year):
return datetime.date(year, month, 13).strftime("%A") == "Friday"
def has_friday_13(month, year):
spooky = datetime.date(year, month, 13)
return spooky.strftime("%A") == "Friday"
import datetime
from datetime import date
def has_friday_13(date):
month, day, year = (int(i) for i in date.split(' '))
spooky = datetime.date(year, month, day)
return spooky.strftime("%A") == "Friday"
import datetime
from datetime import datetime
import calendar
def has_friday_13(month, year):
date = f'{month} 13 {year}'.format()
spooky = datetime.strptime(date, '%m %d %Y').weekday()
return (calendar.day_name[spooky]) == "Friday"
import datetime
from datetime import datetime
import calendar
def has_friday_13(month, year):
date = f'{month} 13 {year}'.format()
spooky = datetime.strptime(date, '%m %d %Y').weekday()
return (calendar.day_name[spooky]) == "Friday"
def outer_func():
x = "local"
def inner_func():
nonlocal x
x = "nonlocal"
print("inner:", x)
inner_func()
print("outer:", x)
a = "global"
b = "global"
a = 2*a
print("Outside of the function",a)
def my_func():
b = 2*b
print("Inside of the function",b)
# https://stackoverflow.com/questions/11619942/print-series-of-prime-numbers-in-python
for num in range(2,10):
if all(num%i!=0 for i in range(2,num)):
print (num)