## Delete all even numbers

0 likes • Nov 19, 2022
Python

## More Python Posts

```# Given a number n, print all primes smaller than or equal to n. It is also given that n is a small number.# For example, if n is 10, the output should be “2, 3, 5, 7”. If n is 20, the output should be “2, 3, 5, 7, 11, 13, 17, 19”.

# Python program to print all primes smaller than or equal to# n using Sieve of Eratosthenes
def SieveOfEratosthenes(n):		# Create a boolean array "prime[0..n]" and initialize	# all entries it as true. A value in prime[i] will	# finally be false if i is Not a prime, else true.	prime = [True for i in range(n + 1)]	p = 2	while (p * p <= n):				# If prime[p] is not changed, then it is a prime		if (prime[p] == True):						# Update all multiples of p			for i in range(p * 2, n + 1, p):				prime[i] = False		p += 1	prime= False	prime= False	# Print all prime numbers	for p in range(n + 1):		if prime[p]:			print (p)
# driver programif __name__=='__main__':    n = 30    print("Following are the prime numbers smaller")    print("than or equal to ", n)    print("than or equal to ", n)    SieveOfEratosthenes(n)```
`""" Number Guessing Game----------------------------------------"""import randomattempts_list = []def show_score():    if len(attempts_list) <= 0:        print("There is currently no high score, it's yours for the taking!")    else:        print("The current high score is {} attempts".format(min(attempts_list)))def start_game():    random_number = int(random.randint(1, 10))    print("Hello traveler! Welcome to the game of guesses!")    player_name = input("What is your name? ")    wanna_play = input("Hi, {}, would you like to play the guessing game? (Enter Yes/No) ".format(player_name))    // Where the show_score function USED to be    attempts = 0    show_score()    while wanna_play.lower() == "yes":        try:            guess = input("Pick a number between 1 and 10 ")            if int(guess) < 1 or int(guess) > 10:                raise ValueError("Please guess a number within the given range")            if int(guess) == random_number:                print("Nice! You got it!")                attempts += 1                attempts_list.append(attempts)                print("It took you {} attempts".format(attempts))                play_again = input("Would you like to play again? (Enter Yes/No) ")                attempts = 0                show_score()                random_number = int(random.randint(1, 10))                if play_again.lower() == "no":                    print("That's cool, have a good one!")                    break            elif int(guess) > random_number:                print("It's lower")                attempts += 1            elif int(guess) < random_number:                print("It's higher")                attempts += 1        except ValueError as err:            print("Oh no!, that is not a valid value. Try again...")            print("({})".format(err))    else:        print("That's cool, have a good one!")if __name__ == '__main__':    start_game()`
`import copybegining = [False,False,False,False,False,None,True,True,True,True,True]#False = black True = whiteits = def swap(layout, step):    layoutCopy = copy.deepcopy(layout)    layoutCopy[(step+step)], layoutCopy[step] = layoutCopy[step], layoutCopy[(step+step)]    return layoutCopydef isSolved(layout):    for i in range(len(layout)):        if(layout[i] == False):            return (i >= (len(layout)/2))def recurse(layout, its, steps = []):    if isSolved(layout):        its += 1        print(layout,list(x for x in steps))        return    step = None    for i in range(len(layout)):        if(layout[i] == None):            if(i >= 1): #If the empty space could have something to the left                if(layout[i - 1] == False):                    step = [-1,i]                    recurse(swap(layout,step), its, (steps+[step]))                if(i > 1): #If the empty space could have something 2 to the left                    if(layout[i - 2] == False):                        step = [-2,i]                        recurse(swap(layout,step), its, (steps+[step]))            if(i < (len(layout)-1)): #If the empty space could have something to the right                if(layout[i + 1] == True):                    step = [1,i]                    recurse(swap(layout,step), its, (steps+[step]))                if(i < (len(layout)-2)): #If the empty space could have something to the right                    if(layout[i + 2] == True):                        step = [2,i]                        recurse(swap(layout,step), its, (steps+[step]))    its += 1    #return Nonerecurse(begining,its,[])print(its)`

### Lonely Integer

wabdelh
0 likes • Feb 26, 2023
Python
`#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    for i in range(1,len(a)):        res = res ^ a[i]`
```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]))```

```# Python program for implementation of Radix Sort	# A function to do counting sort of arr[] according to# the digit represented by exp.def countingSort(arr, exp1):		n = len(arr)		# The output array elements that will have sorted arr	output =  * (n)		# initialize count array as 0	count =  * (10)		# Store count of occurrences in count[]	for i in range(0, n):		index = (arr[i]/exp1)		count[int((index)%10)] += 1		# Change count[i] so that count[i] now contains actual	# position of this digit in output array	for i in range(1,10):		count[i] += count[i-1]		# Build the output array	i = n-1	while i>=0:		index = (arr[i]/exp1)		output[ count[ int((index)%10) ] - 1] = arr[i]		count[int((index)%10)] -= 1		i -= 1		# Copying the output array to arr[],	# so that arr now contains sorted numbers	i = 0	for i in range(0,len(arr)):		arr[i] = output[i]