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 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: |
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 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: |
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 has_friday_13(month, year): | |
return datetime.date(year, month, 13).strftime("%A") == "Friday" |
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 has_friday_13(month, year): | |
spooky = datetime.date(year, month, 13) | |
return spooky.strftime("%A") == "Friday" |
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
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" |
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
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" |
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
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" |
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 outer_func(): | |
x = "local" | |
def inner_func(): | |
nonlocal x | |
x = "nonlocal" | |
print("inner:", x) | |
inner_func() | |
print("outer:", x) |
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
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) |
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
# 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) |