Loading...
More Python Posts
import stringdef caesar(text, shift, alphabets):def shift_alphabet(alphabet):return alphabet[shift:] + alphabet[:shift]shifted_alphabets = tuple(map(shift_alphabet, alphabets))final_alphabet = "".join(alphabets)final_shifted_alphabet = "".join(shifted_alphabets)table = str.maketrans(final_alphabet, final_shifted_alphabet)return text.translate(table)plain_text = "Hey Skrome, welcome to CodeCatch"print(caesar(plain_text, 8, [string.ascii_lowercase, string.ascii_uppercase, string.punctuation]))
#SetsU = {0,1,2,3,4,5,6,7,8,9}P = {1,2,3,4}Q = {4,5,6}R = {3,4,6,8,9}def set2bits(xs,us) :bs=[]for x in us :if x in xs :bs.append(1)else:bs.append(0)assert len(us) == len(bs)return bsdef union(set1,set2) :finalSet = set()bitList1 = set2bits(set1, U)bitList2 = set2bits(set2, U)for i in range(len(U)) :if(bitList1[i] or bitList2[i]) :finalSet.add(i)return finalSetdef intersection(set1,set2) :finalSet = set()bitList1 = set2bits(set1, U)bitList2 = set2bits(set2, U)for i in range(len(U)) :if(bitList1[i] and bitList2[i]) :finalSet.add(i)return finalSetdef compliment(set1) :finalSet = set()bitList = set2bits(set1, U)for i in range(len(U)) :if(not bitList[i]) :finalSet.add(i)return finalSetdef implication(a,b):return union(compliment(a), b)################################################################################################################# Problems 1-6 ###################################################################################################################################p \/ (q /\ r) = (p \/ q) /\ (p \/ r)def prob1():return union(P, intersection(Q,R)) == intersection(union(P,Q), union(P,R))#p /\ (q \/ r) = (p /\ q) \/ (p /\ r)def prob2():return intersection(P, union(Q,R)) == union(intersection(P,Q), intersection(P,R))#~(p /\ q) = ~p \/ ~qdef prob3():return compliment(intersection(P,R)) == union(compliment(P), compliment(R))#~(p \/ q) = ~p /\ ~qdef prob4():return compliment(union(P,Q)) == intersection(compliment(P), compliment(Q))#(p=>q) = (~q => ~p)def prob5():return implication(P,Q) == implication(compliment(Q), compliment(P))#(p => q) /\ (q => r) => (p => r)def prob6():return implication(intersection(implication(P,Q), implication(Q,R)), implication(P,R))print("Problem 1: ", prob1())print("Problem 2: ", prob2())print("Problem 3: ", prob3())print("Problem 4: ", prob4())print("Problem 5: ", prob5())print("Problem 6: ", prob6())'''Problem 1: TrueProblem 2: TrueProblem 3: TrueProblem 4: TrueProblem 5: TrueProblem 6: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}'''
"""Take screenshots at x interval - make a movie of doings on a computer."""import timefrom datetime import datetimeimport ffmpegimport pyautoguiwhile True:epoch_time = int(time.time())today = datetime.now().strftime("%Y_%m_%d")filename = str(epoch_time) + ".png"print("taking screenshot: {0}".format(filename))myScreenshot = pyautogui.screenshot()myScreenshot.save(today + "/" + filename)time.sleep(5)## and then tie it together with: https://github.com/kkroening/ffmpeg-python/blob/master/examples/README.md#assemble-video-from-sequence-of-frames#"""import ffmpeg(ffmpeg.input('./2021_01_22/*.png', pattern_type='glob', framerate=25).filter('deflicker', mode='pm', size=10).filter('scale', size='hd1080', force_original_aspect_ratio='increase').output('movie.mp4', crf=20, preset='slower', movflags='faststart', pix_fmt='yuv420p').run())"""
from itertools import productV='∀'E='∃'def tt(f,n) :xss=product((0,1),repeat=n)print('function:',f.__name__)for xs in xss : print(*xs,':',int(f(*xs)))print('')# p \/ (q /\ r) = (p \/ q) /\ (p \/ r)def prob1(p,q,r) :x=p or (q and r)y= (p or q) and (p or r)return x==ytt(prob1,3)# p/\(q\/r)=(p/\q)\/(p/\r)def prob2(p,q,r) :x=p and ( q or r )y=(p and q) or (p and r)return x==ytt(prob2,3)#~(p/\q)=(~p\/~q)def prob3(p,q) :x=not (p and q)y=(not p) or (not q)return x==ytt(prob3,2)#(~(p\/q))=((~p)/\~q)def prob4(p, q):x = not(p or q)y = not p and not qreturn x == ytt(prob4, 2)#(p/\(p=>q)=>q)def prob5(p,q):x= p and ( not p or q)return not x or qtt(prob5,2)# (p=>q)=((p\/q)=q)def prob6(p,q) :x = (not p or q)y=((p or q) == q)return x==ytt(prob6,2)#((p=>q)=(p\/q))=qdef prob7(p,q):if ((not p or q)==(p or q))==q:return 1tt(prob7,2)#(p=>q)=((p/\q)=p)def prob8(p,q):if (not p or q)==((p and q)==p):return 1tt(prob8,2)#((p=>q)=(p/\q))=pdef prob9(p,q):if ((not p or q)==(p and q))==p:return '1'tt(prob9,2)#(p=>q)/\(q=>r)=>(p=>r)def prob10(p,q,r) :x = not ((not p or q) and (not q or r)) or (not p or r)return xtt(prob10, 3)# (p = q) /\ (q => r) => (p => r)#answer 1def prob11(p,q,r) :x = not((p is q) and (not q or r)) or (not p or r)return xtt(prob11, 3)#(p=q)/\(q=>r)=>(p=>r)#answer 2def prob11(p,q,r):x=(p==q) and (not q or r)y=not p or rreturn not x or ytt(prob11,3)#((p=>q)/\(q=r))=>(p=>r)def prob12(p,q,r):x=(not p or q) and ( q==r )y=not p or rreturn not x or ytt(prob12,3)#(p=>q)=>((p/\r)=>(q/\r))def prob13(p,q,r):x=not p or qy=(not(p and r) or ( q and r))return not x or ytt(prob13,3)#Question#2----------------------------------------#(p=>q)=>r=p=>(q=>r)def prob14(p,q,r):x=(not(not p or q) or r)y=(not p or (not q or r))return x==ytt(prob14,3)def prob15(p, q):x = not(p and q)y = not p and not qreturn x == ytt(prob15, 2)def prob16(p, q):x = not(p or q)y = not p or not qreturn x == ytt(prob16, 2)def prob17(p):x = py = not preturn x == ytt(prob17, 1)
prime_lists=[] # a list to store the prime numbersdef prime(n): # define prime numbersif n <= 1:return False# divide n by 2... up to n-1for i in range(2, n):if n % i == 0: # the remainder should'nt be a 0return Falseelse:prime_lists.append(n)return Truefor n in range(30,1000): # calling function and passing starting point =30 coz we need primes >30prime(n)check=0 # a var to limit the output to 10 onlyfor n in prime_lists:for x in prime_lists:val= n *xif (val > 1000 ):check=check +1if (check <10) :print("the num is:", val , "=",n , "* ", x )break
""" Calculator----------------------------------------"""def addition ():print("Addition")n = float(input("Enter the number: "))t = 0 //Total number enterans = 0while n != 0:ans = ans + nt+=1n = float(input("Enter another number (0 to calculate): "))return [ans,t]def subtraction ():print("Subtraction");n = float(input("Enter the number: "))t = 0 //Total number entersum = 0while n != 0:ans = ans - nt+=1n = float(input("Enter another number (0 to calculate): "))return [ans,t]def multiplication ():print("Multiplication")n = float(input("Enter the number: "))t = 0 //Total number enterans = 1while n != 0:ans = ans * nt+=1n = float(input("Enter another number (0 to calculate): "))return [ans,t]def average():an = []an = addition()t = an[1]a = an[0]ans = a / treturn [ans,t]// main...while True:list = []print(" My first python program!")print(" Simple Calculator in python by Malik Umer Farooq")print(" Enter 'a' for addition")print(" Enter 's' for substraction")print(" Enter 'm' for multiplication")print(" Enter 'v' for average")print(" Enter 'q' for quit")c = input(" ")if c != 'q':if c == 'a':list = addition()print("Ans = ", list[0], " total inputs ",list[1])elif c == 's':list = subtraction()print("Ans = ", list[0], " total inputs ",list[1])elif c == 'm':list = multiplication()print("Ans = ", list[0], " total inputs ",list[1])elif c == 'v':list = average()print("Ans = ", list[0], " total inputs ",list[1])else:print ("Sorry, invilid character")else:break