Last active
September 20, 2017 04:33
-
-
Save meggangreen/ede21df2409a7c62e5e2da00ad099576 to your computer and use it in GitHub Desktop.
HB-Prework-1.py created by meggangreen - https://repl.it/LUvV/10
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 greetings(): | |
print '"no one ever expects the Spanish Inquisition"\n' | |
def txt_to_num(numstr): | |
# https://www.pydanny.com/why-doesnt-python-have-switch-case.html | |
switcher = { | |
'zero': 0, | |
'one': 1, | |
'two': 2, | |
'three': 3, | |
'four': 4, | |
'five': 5, | |
'six': 6, | |
'seven': 7, | |
'eight': 8, | |
'nine': 9, | |
} | |
return switcher.get(numstr, 'LIES') | |
def nosey(): | |
nameF = raw_input('First name, please. ') | |
nameF = nameF[0].upper() + nameF[1:] | |
nameL = raw_input('Last name, please. ') | |
nameL = nameL[0].upper() + nameL[1:] | |
nameComplete = 'Okay ' + nameF + ' ' + nameL + ', IF that\'s your real name, ' | |
fave_color = raw_input('\'Y\' or \'N\', green is the best color. ') | |
if fave_color != 'Y' and fave_color != 'y' : | |
fave_color = 'you clearly don\'t know much about color. ' | |
print 'Green is clearly the best color.' | |
else : | |
fave_color = 'you\'ve passed the color test. ' | |
print 'Hmm, you seem to know something about color.' | |
npets = raw_input('How many pets do you keep?' ) | |
# users might try to be tricky and enter a text representation of a number or a ridulous number or just ridiculousness; let's test | |
try: | |
int(npets) | |
except: | |
npets = txt_to_num(npets) | |
try: | |
int(npets) | |
except: | |
npets = -1 | |
if int(npets) < 0 or int(npets) > 9 : | |
npets = 'Well, no matter. You have no pets and are therefore deemed untrustworthy. Goodbye.' | |
print 'That is preposterous. You don\'t have any pets.' | |
else : | |
npets = 'Pets?! You\'ll need to proceed immediately to quarantine. Shoo!' | |
print 'Good for you; pets are good for the soul.' | |
print nameComplete + fave_color + '\n' + npets + '\n\n' | |
def format_py(): | |
paragraph = """An invitation to dinner was soon afterwards dispatched; | |
and already had Mrs. Bennet planned the courses that were to do credit | |
to her housekeeping, when an answer arrived which deferred it all. Mr. | |
Bingley was obliged to be in town the following day, and, consequently, | |
unable to accept the honour of their invitation, etc. Mrs. Bennet was | |
quite disconcerted.""" | |
average_rating = 4.56789123 | |
print '{:.10s}{}'.format(paragraph, '...') | |
# it keeps rounding! idk how to fix it with ONLY the formatting avail on pyFormat | |
print '{:.2f}'.format(average_rating) | |
###### | |
greetings() | |
nosey() | |
format_py() | |
# Discussion Question: | |
# Why is the following Python invalid? | |
# 'first_name = "Sally"' | |
# 'first_name[0] = "C"' | |
# Although strings are stored as lists, the individual items are immutable. | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment