Announcements
- Project scoping
- Meetups: credit for 2 for longer events. Programming meetups. vs. more general technology workshops.
- Segue: Reagan Moore peer observation & iRODS intro
Class today
- Show and tells
- Class 6 make-up
Homework
A Simple Flask Blog, deployed to Heroku.
Show and tells:
#1
near_hundred
Madeline:
def near_hundred(n):
# If abs within 10 of 100
if abs(n) >= 90 and abs(n) <= 100:
return True
if abs(n) >= 100 and abs(n) <= 110:
return True
# If abs within 10 of 200
if abs(n) >= 190 and abs(n) <= 200:
return True
if abs(n) >= 200 and abs(n) <= 210:
return True
else:
return False
Xuxiang:
def near_hundred(n):
return abs(n - 100) <= 10 or abs(n - 200) <= 10
caught_speeding
Brendan:
def caught_speeding(speed, is_birthday):
if is_birthday:
bonus = 5
else:
bonus = 0
if speed <= (60 + bonus):
ticket = 0
elif speed >= (61 + bonus) and speed <= (80 + bonus):
ticket = 1
elif speed >= (81 + bonus):
ticket = 2
else:
return "Error!"
return ticket
Sunhwa:
def caught_speeding(speed, is_birthday):
if is_birthday==True :
if speed <=65:
return 0
elif speed >=66 and speed <=85:
return 1
else:
return 2
else:
if speed <=60:
return 0
elif speed >=61 and speed <=80:
return 1
else:
return 2
Zach:
def caught_speeding(speed, is_birthday):
if is_birthday:
speed -=5
if speed <= 60:
return 0
if speed >= 81:
return 2
if speed > 60:
return 1
Yonghao:
def caught_speeding(speed, is_birthday):
if is_birthday:
plus_speed=5
else:
plus_speed=0
if speed<=60+plus_speed:
return 0
elif speed<=80+plus_speed:
return 1
else:
return 2
Chunxi:
def caught_speeding(speed, is_birthday):
boon = 0
if is_birthday == True:
boon = 5
if speed <= 60+boon:
return 0
elif speed >= 81+boon:
return 2
else:
return 1
Jacob:
def caught_speeding(speed, is_birthday):
lucky = speed + 5
if is_birthday == True:
if speed < 66:
return 0
elif lucky >= 65 and speed <= 86:
return 1
else:
return 2
else:
if speed < 61:
return 0
elif speed >= 60 and speed <= 80:
return 1
else:
return 2
date_fashion
Sophia:
def date_fashion(you, date):
yes = 2
no = 0
maybe = 1
if you <=2 or date <=2:
return no
elif you >= 8 or date >= 8:
return yes
else:
return maybe
Katie:
def date_fashion(you, date):
if (you >= 8 or date >= 8) and you >2 and date >2: #At least one of you is stylish!
return 2
elif you <= 2 or date <= 2: #Your date let you down...
return 0
else:
return 1
Brittany:
def date_fashion(you, date):
if you <= 2 or date <= 2:
return 0
elif you >= 8 or date >= 8:
return 2
else:
return 1
Mandy:
def date_fashion(you, date):
if you <= 2 or date <= 2:
result = 0
return result
elif you >= 8 or date >= 8:
result = 2
return result
else:
result = 1
return result
alarm_clock
Madeline:
def alarm_clock(day, vacation):
# if vacation and weekend
if vacation == True and day == 0:
return "off"
if vacation == True and day == 6:
return "off"
# if weekday
if not vacation and day >= 1 and day <= 5:
return "7:00"
# if weekend
if not vacation and day == 0 or day == 6:
return "10:00"
# if vacation and weekday
if vacation == True and day >= 1 and day <= 5:
return "10:00"
Sophia:
def alarm_clock(day, vacation):
if day > 0 and day < 6 and vacation == True:
return "10:00"
elif vacation == True and (day == 0 or day == 6):
return "off"
elif vacation == False and day > 0 and day < 6:
return "7:00"
else:
return "10:00"
Allen:
def alarm_clock(day, vacation):
if(day != 0 and day != 6 and not vacation):
return "7:00"
if((day == 0 or day == 6) and not vacation) or (day != 0 and day !=6 and vacation):
return "10:00"
return "off"
cigar_party
Katie:
def cigar_party(cigars, is_weekend):
if is_weekend == True:
if cigars >= 40: #Unlimited cigars on the weekend!
return True
else:
return False
else:
if cigars >= 40 and cigars <= 60: #Take it easy, it's a school night
return True
else:
return False
Jessica:
def cigar_party(cigars, is_weekend):
if is_weekend:
return cigars>=40
else:
return (cigars>=40) and (cigars<=60)
Brittany Refactoring front_back
def front_back(str):
chars = list(str)
index = 0
temp_string = ''
if len(str) <= 1: ##initially had if len(str) == 1, which causes error for blank str
return str
else:
while index < len(str):
if (index > 0) and (index < len(str)-1):
temp_string = temp_string + chars[index]
#print temp_string
index = index + 1
#print index
else:
index = index + 1
#print index
final_string = chars[len(str)-1]+temp_string+chars[0]
return final_string
Using slicing to replace the while
loop:
def front_back(str):
if len(str)-1 == 0:
return str
else:
first_char = str[0:1]
last_char = str[len(str)-1:len(str)]
new_string = last_char + str[1:len(str)-1] + first_char
return new_string
Brittany Refactoring make_out
def make_out_word(out, word):
chars = list(out)
index = 0
new_word = ''
for char in chars:
if index < (len(out)/2):
new_word = new_word + chars[index]
index = index + 1
elif index == (len(out)/2):
new_word = new_word + word + chars[index]
index = index + 1
elif index > (len(out)/2):
new_word = new_word + chars[index]
index = index + 1
else:
index = index + 1
return new_word
def make_out_word(out, word):
out_front = out[0: len(out)/2]
out_back = out[(len(out)/2):(len(out))]
new_word = out_front + word + out_back
return new_word
Lei Wang Refactoring has23
def has23(nums):
if nums[0]==2 or nums[1]==2 or nums[0]==3 or nums[1]==3:
return True
return False
Using in
to replace the series of similar or
comparisons:
def has23(nums):
if 2 in nums or 3 in nums:
return True
return False
Laura was able to make this even simpler with logic:
def has23(nums):
return 2 in nums or 3 in nums