from captcha.image import ImageCaptcha
image = ImageCaptcha(width = 280, height = 90)
captcha_text = 'python'
data = image.generate(captcha_text)
image.write(captcha_text,'CAPTCHA.png')
Solve Problems by Coding Solutions - A Complete solution for python programming
from captcha.image import ImageCaptcha
image = ImageCaptcha(width = 280, height = 90)
captcha_text = 'python'
data = image.generate(captcha_text)
image.write(captcha_text,'CAPTCHA.png')
R = 3
C = 3
def minCost(cost, m, n):
tc = [[0 for x in range(C)] for x in range(R)]
tc[0][0] = cost[0][0]
for i in range(1, m + 1):
tc[i][0] = tc[i-1][0] + cost[i][0]
for j in range(1, n + 1):
tc[0][j] = tc[0][j-1] + cost[0][j]
for i in range(1, m + 1):
for j in range(1, n + 1):
tc[i][j] = min(tc[i-1][j-1], tc[i-1][j],tc[i][j-1]) + cost[i][j]
return tc[m][n]
cost = [[1, 2, 3],
[4, 8, 2],
[1, 5, 3]]
print(minCost(cost, 2, 2))
sample_tuple = ((4, 'Gfg', 10), (3, 'is', 8), (6, 'Best', 10))
print("The original tuple : " + str(sample_tuple))
res = [{'key': sub[0], 'value': sub[1], 'id': sub[2]} for sub in sample_tuple]
print("The converted dictionary : " + str(res))
from itertools import permutations
def allPermutations(str):
permList = permutations(str)
for perm in list(permList):
print (''.join(perm))
if __name__ == "__main__":
str = 'ABC'
allPermutations(str)
import re
def Validate_It(IP):
regex = "(([0-9]|[1-9][0-9]|1[0-9][0-9]|"\
"2[0-4][0-9]|25[0-5])\\.){3}"\
"([0-9]|[1-9][0-9]|1[0-9][0-9]|"\
"2[0-4][0-9]|25[0-5])"
regex1 = "((([0-9a-fA-F]){1,4})\\:){7}"\
"([0-9a-fA-F]){1,4}"
p = re.compile(regex)
p1 = re.compile(regex1)
if (re.search(p, IP)):
return "Valid IPv4"
elif (re.search(p1, IP)):
return "Valid IPv6"
return "Invalid IP"
IP = "203.120.223.13"
print(Validate_It(IP))
IP = "fffe:3465:efab:23fe:2235:6565:aaab:0001"
print(Validate_It(IP))
IP = "2F33:12a0:3Ea0:0302"
print(Validate_It(IP))