Preparing git repo for final project
This commit is contained in:
12
problems/pset1/bank/bank.py
Normal file
12
problems/pset1/bank/bank.py
Normal file
@@ -0,0 +1,12 @@
|
||||
def main():
|
||||
greeting = input("Greeting:\t\t").lower().strip()
|
||||
if greeting.startswith("hello"):
|
||||
print("$0")
|
||||
elif greeting.startswith("h"):
|
||||
print("$20")
|
||||
else:
|
||||
print("$100")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
28
problems/pset1/deep/deep.py
Normal file
28
problems/pset1/deep/deep.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import re
|
||||
answer_regex = re.compile(r"\s*(42|forty[ -]?two)\s*", re.IGNORECASE)
|
||||
|
||||
def ifelse_answer():
|
||||
answer = input("What is the Answer to the Great Question of Life, the Universe, and Everything?\t\t")
|
||||
answer = answer.strip()
|
||||
answer = answer.replace('-', '')
|
||||
answer = answer.replace(' ', '')
|
||||
answer = answer.lower()
|
||||
if answer in ('42', 'fortytwo'):
|
||||
print("Yes")
|
||||
else:
|
||||
print("No")
|
||||
|
||||
|
||||
def regex_answer():
|
||||
print('Yes'
|
||||
if answer_regex.match(
|
||||
input("What is the Answer to the Great Question of Life, the Universe, and Everything?\t\t"))
|
||||
else 'No')
|
||||
|
||||
|
||||
def oneliner():
|
||||
print({True: 'Yes', False: 'No'}[input("What is the Answer to the Great Question of Life, the Universe, and Everything?\t\t").lower().strip() in ('42', 'fortytwo', 'forty two', 'forty-two')])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
regex_answer()
|
22
problems/pset1/extensions/extensions.py
Normal file
22
problems/pset1/extensions/extensions.py
Normal file
@@ -0,0 +1,22 @@
|
||||
extensions = {
|
||||
".gif": "image/gif",
|
||||
".jpg": "image/jpeg",
|
||||
".jpeg": "image/jpeg",
|
||||
".png": "image/png",
|
||||
".pdf": "application/pdf",
|
||||
".txt": "text/plain",
|
||||
".zip": "application/zip"
|
||||
}
|
||||
|
||||
def main():
|
||||
file_name = input("Enter file name:\t\t").lower().strip()
|
||||
for extension, mime in extensions.items():
|
||||
if file_name.endswith(extension):
|
||||
print(mime)
|
||||
break
|
||||
else:
|
||||
print("application/octet-stream")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
17
problems/pset1/interpreter/interpreter.py
Normal file
17
problems/pset1/interpreter/interpreter.py
Normal file
@@ -0,0 +1,17 @@
|
||||
def main():
|
||||
expression = input("Enter an arithmetic expression:\t\t")
|
||||
x, y, z = expression.split()
|
||||
result = 0.0
|
||||
if y == '+':
|
||||
result = int(x) + int(z)
|
||||
elif y == '-':
|
||||
result = int(x) - int(z)
|
||||
elif y == '*':
|
||||
result = int(x) * int(z)
|
||||
elif y == '/':
|
||||
result = int(x) / int(z)
|
||||
print(round(float(result), 1))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
17
problems/pset1/meal/meal.py
Normal file
17
problems/pset1/meal/meal.py
Normal file
@@ -0,0 +1,17 @@
|
||||
def main():
|
||||
t = convert(input("What time is it?\t\t"))
|
||||
if 7 <= t <= 8:
|
||||
print("breakfast time")
|
||||
elif 12 <= t <= 13:
|
||||
print("lunch time")
|
||||
elif 18 <= t <= 19:
|
||||
print("dinner time")
|
||||
|
||||
|
||||
def convert(time):
|
||||
h ,m = map(int, time.split(":"))
|
||||
return float(h + m / 60)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Reference in New Issue
Block a user