This file contains 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 | |
for i in range(5): | |
print(random.randint(1, 10)) |
This file contains 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 sys | |
while True: | |
print('Type exit to exit.') | |
response = input() | |
if response == 'exit': | |
sys.exit() | |
print('You typed '+response+'.') |
This file contains 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 | |
guess = '' | |
count = 0 | |
flag = True | |
while guess not in ('h', 't') and flag == True: | |
guess = input('\nGuess the coin toss! Enter heads or tails:') | |
guess = 1 if guess == 'h' else 0 | |
toss = random.randint(0, 1) # 0 is tails, 1 is heads |
This file contains 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
#pdf open/read | |
#parse | |
import PyPDF2 as pdf | |
def pdfRead(file): | |
pdfobj = open(file, 'rb') | |
pdfread = pdf.PdfFileReader(pdfobj) | |
totpages = pdfread.numPages |
This file contains 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 spin_words(sentence): | |
# Your code goes here | |
words = sentence.split(' ')#[::-1] | |
newL = list() | |
for word in words: | |
newL.append(word) if len(word)<5 else newL.append(word[::-1]) | |
return ' '.join(newL) |
This file contains 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
#'sroirraw wollef Hey' should equal 'Hey wollef sroirraw' | |
def spin_words(sentence): | |
# Your code goes here | |
words = sentence.split(' ')[::-1] | |
newL = list() | |
for word in words: | |
newL.append(word) if len(word)<5 else newL.append(word[::-1]) | |
return ' '.join(newL) |
This file contains 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
#remove vowels | |
def disemvowel(s): | |
return s.translate(None, "aeiouAEIOU") | |
def disemvowel(string): | |
return "".join(c for c in string if c.lower() not in "aeiou") |
This file contains 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
""" | |
ATM machines allow 4 or 6 digit PIN codes and PIN codes cannot contain anything but exactly 4 digits or exactly 6 digits. | |
If the function is passed a valid PIN string, return true, else return false. | |
""" | |
def validate_pin(pin): | |
#return true or false | |
return pin.isdigit() and (len(pin) == 4 or len(pin) == 6) | |
#OR |
This file contains 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
""" | |
Simple, given a string of words, return the length of the shortest word(s). | |
String will never be empty and you do not need to account for different data types. | |
""" | |
def find_short(s): | |
# your code here | |
l = min([len(x) for x in s.split()]) | |
return l # l: shortest word length |
This file contains 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
""" | |
Your goal in this kata is to implement a difference function, which subtracts one list from another and returns the result. | |
It should remove all values from list a, which are present in list b. | |
""" | |
def array_diff(a, b): | |
#your code here | |
return [x for x in a if x not in b] |
OlderNewer