• Jun 1, 2023 •CodeCatch
0 likes • 3 views
def calculate_values(): value1 = 10 value2 = 20 return value1, value2 result1, result2 = calculate_values() print("Result 1:", result1) print("Result 2:", result2)
• Nov 19, 2022 •CodeCatch
0 likes • 0 views
# Python program for implementation of Bogo Sort import random # Sorts array a[0..n-1] using Bogo sort def bogoSort(a): n = len(a) while (is_sorted(a)== False): shuffle(a) # To check if array is sorted or not def is_sorted(a): n = len(a) for i in range(0, n-1): if (a[i] > a[i+1] ): return False return True # To generate permuatation of the array def shuffle(a): n = len(a) for i in range (0,n): r = random.randint(0,n-1) a[i], a[r] = a[r], a[i] # Driver code to test above a = [3, 2, 4, 1, 0, 5] bogoSort(a) print("Sorted array :") for i in range(len(a)): print ("%d" %a[i]),
• Mar 12, 2021 •mo_ak
0 likes • 2 views
prime_lists=[] # a list to store the prime numbers def prime(n): # define prime numbers if n <= 1: return False # divide n by 2... up to n-1 for i in range(2, n): if n % i == 0: # the remainder should'nt be a 0 return False else: prime_lists.append(n) return True for n in range(30,1000): # calling function and passing starting point =30 coz we need primes >30 prime(n) check=0 # a var to limit the output to 10 only for n in prime_lists: for x in prime_lists: val= n *x if (val > 1000 ): check=check +1 if (check <10) : print("the num is:", val , "=",n , "* ", x ) break
• Mar 10, 2021 •Skrome
import string def 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]))
0 likes • 18 views
def sum_of_powers(end, power = 2, start = 1): return sum([(i) ** power for i in range(start, end + 1)]) sum_of_powers(10) # 385 sum_of_powers(10, 3) # 3025 sum_of_powers(10, 3, 5) # 2925
• May 31, 2023 •CodeCatch
# Prompt user for a decimal number decimal = int(input("Enter a decimal number: ")) # Convert decimal to binary binary = bin(decimal) # Convert decimal to hexadecimal hexadecimal = hex(decimal) # Display the results print("Binary:", binary) print("Hexadecimal:", hexadecimal)