Skip to content

Instantly share code, notes, and snippets.

@leonchen417
Created January 17, 2017 22:59
Show Gist options
  • Save leonchen417/bafb7d61d47245100d92a6b7367daea4 to your computer and use it in GitHub Desktop.
Save leonchen417/bafb7d61d47245100d92a6b7367daea4 to your computer and use it in GitHub Desktop.
HW4 created by leonchen417 - https://repl.it/FKH6/32
guess_me =7
start = 1
while True:
if guess_me>start:
print('too low',start)
elif guess_me == start:
print('found it',start)
else:
print('too high',start)
break
start+=1
toprintlist = [3,2,1,0]
for num in toprintlist:
print(num)
#lis,dict comprehension : range 1-10 even number
print( [num for num in range(1,10) if num %2==0])
#key:key^2 as value
dicttest = {key: key**2 for key in range(1,10)}
print(dicttest)
settest = {key for key in range(1,10) if key %2 ==1}
print(settest)
#generator comprehension
X = (number for number in range(1,10) if number%2 ==1)
for num in X:
print('Got ',num)
#decorator
def decorateIt(func):
def new_func(*args,**kwargs):
print('start')
result = func(*args,**kwargs)
print('end')
return result
return new_func
@decorateIt
def add_int(a,b):
return a+b
class OopsException(Exception):
print('Ah Ha got you!')
pass
'''
testwords = ['lalala','rororo','RORORO']
for word in testwords:
if word.isupper():
raise OopsException(word,'is not uppercase Ah HA!')
'''
items1 = ["blue", "red", "green", "white"]
items2 = ["sky", "sunset", "lawn", "pillow"]
# Zip the two lists and access pairs together.
for item1, item2 in zip(items1, items2):
print(item1, "...", item2)
title = ['Creature of Habit','Crewel Fate']
plot = ['A nun turns into a monster','A haunted yarn shop']
dictionary = dict(zip(title, plot))
print(dictionary)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment