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]))
primes=[]products=[]def prime(num):if num > 1:for i in range(2,num):if (num % i) == 0:return Falseelse:primes.append(num)return Truefor n in range(30,1000):if len(primes) >= 20:break;else:prime(n)for previous, current in zip(primes[::2], primes[1::2]):products.append(previous * current)print (products)
bytes_data = b'Hello, World!'string_data = bytes_data.decode('utf-8')print("String:", string_data)
#84 48 13 20 61 20 33 97 34 45 6 63 71 66 24 57 92 74 6 25 51 86 48 15 64 55 77 30 56 53 37 99 9 59 57 61 30 97 50 63 59 62 39 32 34 4 96 51 8 86 10 62 16 55 81 88 71 25 27 78 79 88 92 50 16 8 67 82 67 37 84 3 33 4 78 98 39 64 98 94 24 82 45 3 53 74 96 9 10 94 13 79 15 27 56 66 32 81 77# xor a list of integers to find the lonely integerres = a[0]for i in range(1,len(a)):res = res ^ a[i]
def hex_to_rgb(hex):return tuple(int(hex[i:i+2], 16) for i in (0, 2, 4))hex_to_rgb('FFA501') # (255, 165, 1)
# importing the modulesimport osimport shutil# getting the current working directorysrc_dir = os.getcwd()# printing current directoryprint(src_dir)# copying the filesshutil.copyfile('test.txt', 'test.txt.copy2') #copy src to dst# printing the list of new filesprint(os.listdir())