This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random | |
| # Generate Lists | |
| list1 = random.sample(range(50), 20) | |
| list2 = random.sample(range(50), 20) | |
| lists_compared = [] | |
| # Compare list a and b, put into a list from a set (compares as a set) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Enter number for divisors here | |
| Num = int(input("What number do you want Divisors for?")) | |
| #Ensure number is positive | |
| if Num <= 0: | |
| print("Number must be positive") | |
| quit() | |
| #create range to work in | |
| range_nums = range(1, Num) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Initiating variables, list is fixed, value is an input from the console | |
| # and result is an empty list to be filled with results | |
| list = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] | |
| value = int(input("what would you like to count to?")) | |
| result = [] | |
| # For loop that compares values in list to value from beginning to end of the list. | |
| # if the value in list is smaller than value then it is appended to the empty list result | |
| for i in range(len(list)): | |
| if list[i] <= value: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Input from console for word to check | |
| word = input("What would you like to check if its a Palindrome?") | |
| #initialise variables | |
| x = 0 | |
| reverse_word = '' | |
| # loop over word until all letters are done | |
| for i in word: | |
| # increment counter | |
| x += 1 | |
| # extend reverse_word with next letter from word (reversed) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import base64 | |
| def hex_to_base64(input): | |
| result = bytearray.fromhex(input) | |
| result = base64.b64encode(result) | |
| result = str(result).strip("'b'") | |
| return result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Values entered must be hex encoded, preface with 0x if not already | |
| def hex_xor(first, second): | |
| result = (first ^ second) | |
| return result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random | |
| list = [] | |
| i = 0 | |
| while i < 100: | |
| list.append(random.randrange(1,40)) | |
| i += 1 | |
| # creating a list with no duplicates using a for loop | |
| def list_no_duplicates(list): | |
| # sorting list to make it pretty |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import string, random | |
| from collections import OrderedDict | |
| from itertools import count | |
| # creating numerically linked dictionaries to pull characters from | |
| lower = OrderedDict(zip(count(1), string.ascii_lowercase)) | |
| upper = OrderedDict(zip(count(27), string.ascii_uppercase)) | |
| symbols = OrderedDict(zip(count(53), (string.punctuation))) | |
| length = int(input("How many characters would you like in your password?")) | |
| i = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random, time | |
| k = 0 | |
| def sorted_list(a, b): | |
| test = random.sample(range(a), b) | |
| test.sort() | |
| return test | |
| def binary_search(sorter, num_find): | |
| print (sorter) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| word = input("In:") | |
| sumof = 0 | |
| x = 0 | |
| for i in word: | |
| if word[x] == "a" or word[x] == "e" or word[x] == "i" or word[x] == "o" or word[x] == "u": | |
| sumof += 1 | |
| x += 1 | |
| print(sumof) |
OlderNewer