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
| def tickets(numbers): | |
| """The new "Avengers" movie has just been released! There are a lot of people at the cinema box office standing | |
| in a huge line. Each of them has a single 100, 50 or 25 dollar bill. An "Avengers" ticket costs 25 dollars. | |
| Return YES, if Vasya can sell a ticket to every person and give change with the bills he has at hand at that | |
| moment. Otherwise return NO """ | |
| money = [] | |
| for number in numbers: | |
| if number == 25: | |
| money.append(number) | |
| try: |
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 re | |
| def camel(phrase): | |
| """Complete the solution so that the function will break up camel casing, using a space between words.""" | |
| regex = re.compile(r'''[A-Z]''') | |
| words = [d for d in phrase] | |
| for word in regex.finditer(phrase): | |
| if " " in words: | |
| # Because of the first insert of " " the indexes have been moved. |
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
| def namelist(names): | |
| """ | |
| Given: an array containing hashes of names | |
| Return: a string formatted as a list of names separated by commas except for the last two names, which should be | |
| separated by an ampersand. More info: https://bit.ly/2O1dmvs""" | |
| list_of_names = [value for name in names for key, value in name.items()] | |
| if len(list_of_names) >= 2: | |
| # Replacing comma in the end of string with ampersand. | |
| return (', '.join(list_of_names)[::-1].replace(",", "& ", 1))[::-1] | |
| else: |
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
| # ! python3 | |
| # mcb.pyw - saves and loads a pieces of text | |
| # to the clipboard. | |
| # Usage: py.exe mcb.pyw save <keyword> - | |
| # Saves the clipboard to a keyword | |
| # py.exe mcb pyw <keyword> - \ | |
| # Loads a keyword to the clipboard | |
| # py.exe mcb.pyw list - \ | |
| # Loads all keywords | |
| # mcb.pyw delete <keyword> - \ |
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
| # Create a Mad Libs program that reads in text files and lets the user add | |
| # their own text anywhere the word ADJECTIVE, NOUN, ADVERB, or VERB | |
| # appears in # the text file. For example, a text file may look like this: | |
| # The ADJECTIVE panda walked to the NOUN and then VERB. A nearby NOUN was | |
| # unaffected by these events. | |
| # The program would find these occurrences and prompt the user to replace them. | |
| with open("ad.txt", "r") as file: |
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
| # Write a program that opens all . txt files in a folder | |
| # and searches for any line that matches a user-supplied regular expression. | |
| # The results should be printed to the screen. | |
| import os | |
| import re | |
| needed_word = input("Write down which word you wanna find: ") | |
| regex = re.compile(f'''{needed_word}''') | |
| for word in os.listdir(): |
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
| #!python3 | |
| """Write a program that walks through a folder tree and searches for files with a certain fileextension (such as | |
| or | |
| .jpg). | |
| Copy these files from whatever location they are in to a new folder.""" | |
| import os | |
| import shutil |
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 os | |
| """Write a program that walks through a folder tree and searches for exceptionally large files or folders — say, | |
| ones that have a file size of more than 100MB. | |
| Print these files with their absolute path to the screen. """ | |
| flag = False | |
| for foldername, subfolder, filename in os.walk(r"C:\Users\python\Desktop"): | |
| folders = [foldername + "\\" + folder for folder in filename] | |
| user_answers_yes = ["y", "yes", "yep", "yeah"] |
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
| #!python3 | |
| import os | |
| import re | |
| """Write a program that finds all files with a given prefix, such as spam001.txt , spam002.txt , | |
| and so on, in a single folder and locates any gaps in the numbering (such as if there is a | |
| spam001.txt and spam003.txt but no spam002.txt ). | |
| Have the program rename all the later files to close this gap.""" |
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
| #!python3 | |
| import os | |
| import re | |
| """As an added challenge, write another program that can insert gaps into numbered files so that a new file can be | |
| added. """ | |
| working_directory = input("Input your working directory with files: ") | |
| numbers = [[correct_number + 1, number_of_file] for foldername, subfolder, filename in |